Coverage for tests/test_tutorial/test_code_structure/test_tutorial002.py: 100%
21 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-16 00:02 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-16 00:02 +0000
1import importlib 1abcdefghijklm
2from dataclasses import dataclass 1abcdefghijklm
3from types import ModuleType 1abcdefghijklm
5import pytest 1abcdefghijklm
6from sqlalchemy import Engine 1abcdefghijklm
8from ...conftest import PrintMock 1abcdefghijklm
10expected_calls = [ 1abcdefghijklm
11 [
12 "Created hero:",
13 {
14 "id": 1,
15 "name": "Deadpond",
16 "age": None,
17 "secret_name": "Dive Wilson",
18 "team_id": 1,
19 },
20 ],
21 [
22 "Hero's team:",
23 {"name": "Z-Force", "headquarters": "Sister Margaret's Bar", "id": 1},
24 ],
25]
28@dataclass 1abcdefghijklm
29class Modules: 1abcdefghijklm
30 app: ModuleType 1abcdefghijklm
31 database: ModuleType 1abcdefghijklm
34@pytest.fixture( 1abcdefghijklm
35 name="modules",
36 params=[
37 pytest.param("tutorial002"),
38 ],
39)
40def get_modules(request: pytest.FixtureRequest, database_engine: Engine) -> Modules: 1abcdefghijklm
41 app_module = importlib.import_module( 1abcdefghijklm
42 f"docs_src.tutorial.code_structure.{request.param}.app"
43 )
44 database_module = importlib.import_module( 1abcdefghijklm
45 f"docs_src.tutorial.code_structure.{request.param}.database"
46 )
47 database_module.engine = database_engine 1abcdefghijklm
48 app_module.engine = database_module.engine 1abcdefghijklm
50 return Modules(app=app_module, database=database_module) 1abcdefghijklm
53def test_tutorial(print_mock: PrintMock, modules: Modules): 1abcdefghijklm
54 modules.app.main() 1nopqrstuvwxyz
55 assert print_mock.calls == expected_calls 1nopqrstuvwxyz