Coverage for tests / test_tutorial / test_fastapi / test_app_testing / test_tutorial001_tests001.py: 100%
24 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 1abcidefgh
2import sys 1abcidefgh
3from dataclasses import dataclass 1abcidefgh
4from types import ModuleType 1abcidefgh
6import pytest 1abcidefgh
8from tests.conftest import needs_py310 1abcidefgh
11@dataclass 1abcidefgh
12class Modules: 1abcidefgh
13 app: ModuleType 1abcidefgh
14 test: ModuleType 1abcidefgh
17@pytest.fixture( 1abcidefgh
18 name="modules_path",
19 params=[
20 pytest.param("tutorial001_py39"),
21 pytest.param("tutorial001_py310", marks=needs_py310),
22 ],
23)
24def get_modules_path(request: pytest.FixtureRequest) -> str: 1abcidefgh
25 return f"docs_src.tutorial.fastapi.app_testing.{request.param}" 1abcidefgh
28@pytest.fixture(name="modules") 1abcidefgh
29def load_modules(clear_sqlmodel, modules_path: str) -> Modules: 1abcidefgh
30 # Trigger side effects of registering table models in SQLModel
31 # This has to be called after clear_sqlmodel
32 app_mod_path = f"{modules_path}.main" 1abcidefgh
33 if app_mod_path in sys.modules: 1abcidefgh
34 app_mod = sys.modules[app_mod_path] 1abcidefgh
35 importlib.reload(app_mod) 1abcidefgh
36 else:
37 app_mod = importlib.import_module(app_mod_path) 1abcdefgh
38 test_mod = importlib.import_module(f"{modules_path}.test_main_001") 1abcidefgh
39 return Modules(app=app_mod, test=test_mod) 1abcidefgh
42def test_tutorial(modules: Modules): 1abcidefgh
43 modules.test.test_create_hero() 1jklmnopqr