Coverage for tests / test_tutorial / test_update / test_tutorial001_tutorial002.py: 100%
20 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-01-06 21:09 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-01-06 21:09 +0000
1import importlib 1abcdefghi
2from types import ModuleType 1abcdefghi
4import pytest 1abcdefghi
5from sqlmodel import create_engine 1abcdefghi
7from ...conftest import PrintMock, needs_py310 1abcdefghi
9expected_calls = [ 1abcdefghi
10 [
11 "Hero:",
12 {
13 "id": 2,
14 "name": "Spider-Boy",
15 "secret_name": "Pedro Parqueador",
16 "age": None,
17 },
18 ],
19 [
20 "Updated hero:",
21 {
22 "id": 2,
23 "name": "Spider-Boy",
24 "secret_name": "Pedro Parqueador",
25 "age": 16,
26 },
27 ],
28]
31@pytest.fixture(name="module") 1abcdefghi
32def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi
33 module = importlib.import_module(f"docs_src.tutorial.update.{request.param}") 1abcdefghi
34 module.sqlite_url = "sqlite://" 1abcdefghi
35 module.engine = create_engine(module.sqlite_url) 1abcdefghi
36 return module 1abcdefghi
39@pytest.mark.parametrize( 1abcdefghi
40 "module",
41 [
42 pytest.param("tutorial001_py39"),
43 pytest.param("tutorial001_py310", marks=needs_py310),
44 ],
45 indirect=True,
46)
47def test_tutorial001(print_mock: PrintMock, module: ModuleType): 1abcdefghi
48 module.main() 1jklmnopqr
49 assert print_mock.calls == expected_calls 1jklmnopqr
52@pytest.mark.parametrize( 1abcdefghi
53 "module",
54 [
55 pytest.param("tutorial002_py39"),
56 pytest.param("tutorial002_py310", marks=needs_py310),
57 ],
58 indirect=True,
59)
60def test_tutorial002(print_mock: PrintMock, module: ModuleType): 1abcdefghi
61 module.main() 1stuvwxyzA
62 assert print_mock.calls == expected_calls 1stuvwxyzA