Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcb4e8c

Browse files
author
Valentyn Druzhynin
committed
Simplify tests for settings tutorial #13504
1 parent 4e40e1e commit dcb4e8c

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

tests/test_tutorial/test_settings/test_tutorial001.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
import importlib
2+
3+
import pytest
14
from fastapi.testclient import TestClient
25
from pytest import MonkeyPatch
36

4-
from ...utils import needs_pydanticv2
7+
from ...utils import needs_pydanticv1
8+
9+
10+
@pytest.fixture(
11+
params=[
12+
"tutorial001",
13+
pytest.param("tutorial001_pv1", marks=needs_pydanticv1),
14+
],
15+
)
16+
def get_app(request: pytest.FixtureRequest):
17+
def app_wrapper():
18+
mod = importlib.import_module(f"docs_src.settings.{request.param}")
19+
return mod.app
20+
21+
return app_wrapper
522

623

7-
@needs_pydanticv2
8-
def test_settings(monkeypatch: MonkeyPatch):
24+
def test_settings(get_app, monkeypatch: MonkeyPatch):
925
monkeypatch.setenv("ADMIN_EMAIL", "[email protected]")
10-
from docs_src.settings.tutorial001 import app
1126

27+
app = get_app()
1228
client = TestClient(app)
1329
response = client.get("/info")
1430
assert response.status_code == 200, response.text

tests/test_tutorial/test_settings/test_tutorial001_pv1.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)