| 1 |
import importlib |
| 2 |
from types import ModuleType |
| 3 |
|
| 4 |
import pytest |
| 5 |
from pytest import MonkeyPatch |
| 6 |
|
| 7 |
|
| 8 |
@pytest.fixture( |
| 9 |
name="mod_path", |
| 10 |
params=[ |
| 11 |
pytest.param("app02_py310"), |
| 12 |
pytest.param("app02_an_py310"), |
| 13 |
], |
| 14 |
) |
| 15 |
def get_mod_path(request: pytest.FixtureRequest): |
| 16 |
mod_path = f"docs_src.settings.{request.param}" |
| 17 |
return mod_path |
| 18 |
|
| 19 |
|
| 20 |
@pytest.fixture(name="main_mod") |
| 21 |
def get_main_mod(mod_path: str) -> ModuleType: |
| 22 |
main_mod = importlib.import_module(f"{mod_path}.main") |
| 23 |
return main_mod |
| 24 |
|
| 25 |
|
| 26 |
@pytest.fixture(name="test_main_mod") |
| 27 |
def get_test_main_mod(mod_path: str) -> ModuleType: |
| 28 |
test_main_mod = importlib.import_module(f"{mod_path}.test_main") |
| 29 |
return test_main_mod |
| 30 |
|
| 31 |
|
| 32 |
def test_settings(main_mod: ModuleType, monkeypatch: MonkeyPatch): |
| 33 |
monkeypatch.setenv("ADMIN_EMAIL", "[email protected]") |
| 34 |
settings = main_mod.get_settings() |
| 35 |
assert settings.app_name == "Awesome API" |
| 36 |
assert settings.items_per_user == 50 |
| 37 |
|
| 38 |
|
| 39 |
def test_override_settings(test_main_mod: ModuleType): |
| 40 |
test_main_mod.test_app() |