Add missing tests for code examples (#14569)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nils-Hero Lindemann <nilsherolindemann@proton.me>
This commit is contained in:
Motov Yurii
2025-12-26 11:43:02 +01:00
committed by GitHub
parent 5eb8d6ed8a
commit 3063ada72f
183 changed files with 10459 additions and 86 deletions

View File

@@ -1,9 +1,20 @@
import importlib
import pytest
from fastapi.testclient import TestClient
from docs_src.first_steps.tutorial001_py39 import app
client = TestClient(app)
@pytest.fixture(
name="client",
params=[
"tutorial001_py39",
"tutorial003_py39",
],
)
def get_client(request: pytest.FixtureRequest):
mod = importlib.import_module(f"docs_src.first_steps.{request.param}")
client = TestClient(mod.app)
return client
@pytest.mark.parametrize(
@@ -13,13 +24,13 @@ client = TestClient(app)
("/nonexistent", 404, {"detail": "Not Found"}),
],
)
def test_get_path(path, expected_status, expected_response):
def test_get_path(client: TestClient, path, expected_status, expected_response):
response = client.get(path)
assert response.status_code == expected_status
assert response.json() == expected_response
def test_openapi_schema():
def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json")
assert response.status_code == 200
assert response.json() == {