Coverage for tests / test_tutorial / test_delete / test_tutorial001_tutorial002.py: 100%
19 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-09 00:02 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-09 00:02 +0000
1import importlib 1abcdefghi
2from types import ModuleType 1abcdefghi
4import pytest 1abcdefghi
5from sqlalchemy import Engine 1abcdefghi
7from ...conftest import PrintMock 1abcdefghi
9expected_calls = [ 1abcdefghi
10 [
11 "Hero 1:",
12 {"id": 2, "name": "Spider-Boy", "secret_name": "Pedro Parqueador", "age": None},
13 ],
14 [
15 "Hero 2:",
16 {
17 "id": 7,
18 "name": "Captain North America",
19 "secret_name": "Esteban Rogelios",
20 "age": 93,
21 },
22 ],
23 [
24 "Updated hero 1:",
25 {
26 "id": 2,
27 "name": "Spider-Youngster",
28 "secret_name": "Pedro Parqueador",
29 "age": 16,
30 },
31 ],
32 [
33 "Updated hero 2:",
34 {
35 "id": 7,
36 "name": "Captain North America Except Canada",
37 "secret_name": "Esteban Rogelios",
38 "age": 110,
39 },
40 ],
41 [
42 "Hero: ",
43 {
44 "id": 2,
45 "name": "Spider-Youngster",
46 "secret_name": "Pedro Parqueador",
47 "age": 16,
48 },
49 ],
50 [
51 "Deleted hero:",
52 {
53 "id": 2,
54 "name": "Spider-Youngster",
55 "secret_name": "Pedro Parqueador",
56 "age": 16,
57 },
58 ],
59 ["There's no hero named Spider-Youngster"],
60]
63@pytest.fixture(name="module") 1abcdefghi
64def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghi
65 module = importlib.import_module(f"docs_src.tutorial.delete.{request.param}") 1abcdefghi
66 module.engine = database_engine 1abcdefghi
67 return module 1abcdefghi
70@pytest.mark.parametrize( 1abcdefghi
71 "module",
72 [
73 pytest.param("tutorial001_py310"),
74 ],
75 indirect=True,
76)
77def test_tutorial001(print_mock: PrintMock, module: ModuleType): 1abcdefghi
78 module.main() 1jklmnopqr
79 assert print_mock.calls == expected_calls 1jklmnopqr
82@pytest.mark.parametrize( 1abcdefghi
83 "module",
84 [
85 pytest.param("tutorial002_py310"),
86 ],
87 indirect=True,
88)
89def test_tutorial002(print_mock: PrintMock, module: ModuleType): 1abcdefghi
90 module.main() 1stuvwxyzA
91 assert print_mock.calls == expected_calls 1stuvwxyzA