Coverage for tests / test_tutorial / test_settings / test_app03.py: 100%
25 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1import importlib 1abdc
2from types import ModuleType 1abdc
4import pytest 1abdc
5from fastapi.testclient import TestClient 1abdc
6from pytest import MonkeyPatch 1abdc
9@pytest.fixture( 1abdc
10 name="mod_path",
11 params=[
12 pytest.param("app03_py310"),
13 pytest.param("app03_an_py310"),
14 ],
15)
16def get_mod_path(request: pytest.FixtureRequest): 1abdc
17 mod_path = f"docs_src.settings.{request.param}" 1abc
18 return mod_path 1abc
21@pytest.fixture(name="main_mod") 1abdc
22def get_main_mod(mod_path: str) -> ModuleType: 1abdc
23 main_mod = importlib.import_module(f"{mod_path}.main") 1abc
24 return main_mod 1abc
27def test_settings(main_mod: ModuleType, monkeypatch: MonkeyPatch): 1abdc
28 monkeypatch.setenv("ADMIN_EMAIL", "admin@example.com") 1efg
29 settings = main_mod.get_settings() 1efg
30 assert settings.app_name == "Awesome API" 1efg
31 assert settings.admin_email == "admin@example.com" 1efg
32 assert settings.items_per_user == 50 1efg
35def test_endpoint(main_mod: ModuleType, monkeypatch: MonkeyPatch): 1abdc
36 monkeypatch.setenv("ADMIN_EMAIL", "admin@example.com") 1hij
37 client = TestClient(main_mod.app) 1hij
38 response = client.get("/info") 1hij
39 assert response.status_code == 200 1hij
40 assert response.json() == { 1hij
41 "app_name": "Awesome API",
42 "admin_email": "admin@example.com",
43 "items_per_user": 50,
44 }