Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Simplify tests for path_operation_configurations #13180

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import importlib

import pytest
from fastapi.testclient import TestClient

from docs_src.path_operation_configuration.tutorial005 import app
from ...utils import needs_py39, needs_py310, needs_pydanticv1, needs_pydanticv2


from ...utils import needs_pydanticv1, needs_pydanticv2
@pytest.fixture(
name="client",
params=[
"tutorial005",
pytest.param("tutorial005_py39", marks=needs_py39),
pytest.param("tutorial005_py310", marks=needs_py310),
],
)
def get_client(request: pytest.FixtureRequest):
mod = importlib.import_module(
f"docs_src.path_operation_configuration.{request.param}"
)

client = TestClient(app)
client = TestClient(mod.app)
return client


def test_query_params_str_validations():
def test_query_params_str_validations(client: TestClient):
response = client.post("/items/", json={"name": "Foo", "price": 42})
assert response.status_code == 200, response.text
assert response.json() == {
Expand All @@ -20,7 +36,7 @@ def test_query_params_str_validations():


@needs_pydanticv2
def test_openapi_schema():
def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == {
Expand Down Expand Up @@ -123,7 +139,7 @@ def test_openapi_schema():

# TODO: remove when deprecating Pydantic v1
@needs_pydanticv1
def test_openapi_schema_pv1():
def test_openapi_schema_pv1(client: TestClient):
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == {
Expand Down

This file was deleted.

Loading
Loading