Coverage for tests / test_tutorial / test_fastapi / test_app_testing / test_tutorial001_tests003.py: 100%
22 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
2import sys 1abcdefgh
3from dataclasses import dataclass 1abcdefgh
4from types import ModuleType 1abcdefgh
6import pytest 1abcdefgh
9@dataclass 1abcdefgh
10class Modules: 1abcdefgh
11 app: ModuleType 1abcdefgh
12 test: ModuleType 1abcdefgh
15@pytest.fixture( 1abcdefgh
16 name="modules_path",
17 params=[
18 pytest.param("tutorial001_py310"),
19 ],
20)
21def get_modules_path(request: pytest.FixtureRequest) -> str: 1abcdefgh
22 return f"docs_src.tutorial.fastapi.app_testing.{request.param}" 1abcdefgh
25@pytest.fixture(name="modules") 1abcdefgh
26def load_modules(clear_sqlmodel, modules_path: str) -> Modules: 1abcdefgh
27 # Trigger side effects of registering table models in SQLModel
28 # This has to be called after clear_sqlmodel
29 app_mod_path = f"{modules_path}.main" 1abcdefgh
30 if app_mod_path in sys.modules: 1abcdefgh
31 app_mod = sys.modules[app_mod_path] 1abcdefgh
32 importlib.reload(app_mod) 1abcdefgh
33 else:
34 app_mod = importlib.import_module(app_mod_path) # pragma: no cover
35 test_mod = importlib.import_module(f"{modules_path}.test_main_003") 1abcdefgh
36 return Modules(app=app_mod, test=test_mod) 1abcdefgh
39def test_tutorial(modules: Modules): 1abcdefgh
40 modules.test.test_create_hero() 1ijklmnop