Coverage for tests / test_tutorial / test_many_to_many / test_tutorial003.py: 100%
15 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-06-10 09:40 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-06-10 09:40 +0000
1import importlib 1abcdefgh
2from types import ModuleType 1abcdefgh
4import pytest 1abcdefgh
5from sqlmodel import create_engine 1abcdefgh
7from ...conftest import PrintMock 1abcdefgh
10@pytest.fixture( 1abcdefgh
11 name="mod",
12 params=[
13 pytest.param("tutorial003_py310"),
14 ],
15)
16def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefgh
17 mod = importlib.import_module(f"docs_src.tutorial.many_to_many.{request.param}") 1abcdefgh
18 mod.sqlite_url = "sqlite://" 1abcdefgh
19 mod.engine = create_engine(mod.sqlite_url) 1abcdefgh
20 return mod 1abcdefgh
23expected_calls = [ 1abcdefgh
24 [
25 "Z-Force hero:",
26 {"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
27 "is training:",
28 False,
29 ],
30 [
31 "Preventers hero:",
32 {"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
33 "is training:",
34 True,
35 ],
36 [
37 "Preventers hero:",
38 {"name": "Spider-Boy", "secret_name": "Pedro Parqueador", "id": 2, "age": None},
39 "is training:",
40 True,
41 ],
42 [
43 "Preventers hero:",
44 {"name": "Rusty-Man", "secret_name": "Tommy Sharp", "id": 3, "age": 48},
45 "is training:",
46 False,
47 ],
48 [
49 "Updated Spider-Boy's Teams:",
50 [
51 {"team_id": 2, "is_training": True, "hero_id": 2},
52 {"team_id": 1, "is_training": True, "hero_id": 2},
53 ],
54 ],
55 [
56 "Z-Force heroes:",
57 [
58 {"team_id": 1, "is_training": False, "hero_id": 1},
59 {"team_id": 1, "is_training": True, "hero_id": 2},
60 ],
61 ],
62 [
63 "Spider-Boy team:",
64 {"headquarters": "Sharp Tower", "id": 2, "name": "Preventers"},
65 "is training:",
66 False,
67 ],
68 [
69 "Spider-Boy team:",
70 {"headquarters": "Sister Margaret's Bar", "id": 1, "name": "Z-Force"},
71 "is training:",
72 True,
73 ],
74]
77def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefgh
78 mod.main() 1ijklmnop
79 assert print_mock.calls == expected_calls 1ijklmnop