Browse Source

Add tests for variants of `settings/app2`

pull/14413/head
Yurii Motov 8 months ago
parent
commit
14f2e2bddb
  1. 43
      tests/test_tutorial/test_settings/test_app02.py

43
tests/test_tutorial/test_settings/test_app02.py

@ -1,20 +1,45 @@
import importlib
from types import ModuleType
import pytest
from pytest import MonkeyPatch from pytest import MonkeyPatch
from ...utils import needs_pydanticv2 from ...utils import needs_py39, needs_pydanticv2
@needs_pydanticv2 @pytest.fixture(
def test_settings(monkeypatch: MonkeyPatch): name="mod_path",
from docs_src.settings.app02 import main params=[
pytest.param("app02"),
pytest.param("app02_an"),
pytest.param("app02_an_py39", marks=needs_py39),
],
)
def get_mod_path(request: pytest.FixtureRequest):
mod_path = f"docs_src.settings.{request.param}"
return mod_path
@pytest.fixture(name="main_mod")
def get_main_mod(mod_path: str) -> ModuleType:
main_mod = importlib.import_module(f"{mod_path}.main")
return main_mod
@pytest.fixture(name="test_main_mod")
def get_test_main_mod(mod_path: str) -> ModuleType:
test_main_mod = importlib.import_module(f"{mod_path}.test_main")
return test_main_mod
@needs_pydanticv2
def test_settings(main_mod: ModuleType, monkeypatch: MonkeyPatch):
monkeypatch.setenv("ADMIN_EMAIL", "[email protected]") monkeypatch.setenv("ADMIN_EMAIL", "[email protected]")
settings = main.get_settings() settings = main_mod.get_settings()
assert settings.app_name == "Awesome API" assert settings.app_name == "Awesome API"
assert settings.items_per_user == 50 assert settings.items_per_user == 50
@needs_pydanticv2 @needs_pydanticv2
def test_override_settings(): def test_override_settings(test_main_mod: ModuleType):
from docs_src.settings.app02 import test_main test_main_mod.test_app()
test_main.test_app()

Loading…
Cancel
Save