Coverage for tests / test_tutorial / test_update / test_tutorial003_tutorial004.py: 100%
20 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
9expected_calls = [ 1abcdefgh
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]
44@pytest.fixture(name="module") 1abcdefgh
45def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefgh
46 module = importlib.import_module(f"docs_src.tutorial.update.{request.param}") 1abcdefgh
47 module.sqlite_url = "sqlite://" 1abcdefgh
48 module.engine = create_engine(module.sqlite_url) 1abcdefgh
49 return module 1abcdefgh
52@pytest.mark.parametrize( 1abcdefgh
53 "module",
54 [
55 pytest.param("tutorial003_py310"),
56 ],
57 indirect=True,
58)
59def test_tutorial003(print_mock: PrintMock, module: ModuleType): 1abcdefgh
60 module.main() 1ijklmnop
61 assert print_mock.calls == expected_calls 1ijklmnop
64@pytest.mark.parametrize( 1abcdefgh
65 "module",
66 [
67 pytest.param("tutorial004_py310"),
68 ],
69 indirect=True,
70)
71def test_tutorial004(print_mock: PrintMock, module: ModuleType): 1abcdefgh
72 module.main() 1qrstuvwx
73 assert print_mock.calls == expected_calls 1qrstuvwx