]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
✅ Simplify tests for dependencies (#13174)
authorAlejandra <90076947+alejsdev@users.noreply.github.com>
Sun, 19 Jan 2025 06:25:51 +0000 (06:25 +0000)
committerGitHub <noreply@github.com>
Sun, 19 Jan 2025 06:25:51 +0000 (06:25 +0000)
25 files changed:
tests/test_tutorial/test_dependencies/test_tutorial001.py
tests/test_tutorial/test_dependencies/test_tutorial001_an.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial001_an_py310.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial001_an_py39.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial001_py310.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial004.py
tests/test_tutorial/test_dependencies/test_tutorial004_an.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial004_an_py310.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial004_an_py39.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial004_py310.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial006.py
tests/test_tutorial/test_dependencies/test_tutorial006_an.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial006_an_py39.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial008b.py
tests/test_tutorial/test_dependencies/test_tutorial008b_an.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial008b_an_py39.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial008c.py
tests/test_tutorial/test_dependencies/test_tutorial008c_an.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial008c_an_py39.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial008d.py
tests/test_tutorial/test_dependencies/test_tutorial008d_an.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial008d_an_py39.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial012.py
tests/test_tutorial/test_dependencies/test_tutorial012_an.py [deleted file]
tests/test_tutorial/test_dependencies/test_tutorial012_an_py39.py [deleted file]

index d1324a64113ed1e2f4ae574d0cb4f3a1b3deb5be..ed9944912e427b4674f1df139ac60cdb62ec92e8 100644 (file)
@@ -1,10 +1,27 @@
+import importlib
+
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
 
-from docs_src.dependencies.tutorial001 import app
+from ...utils import needs_py39, needs_py310
+
+
+@pytest.fixture(
+    name="client",
+    params=[
+        "tutorial001",
+        pytest.param("tutorial001_py310", marks=needs_py310),
+        "tutorial001_an",
+        pytest.param("tutorial001_an_py39", marks=needs_py39),
+        pytest.param("tutorial001_an_py310", marks=needs_py310),
+    ],
+)
+def get_client(request: pytest.FixtureRequest):
+    mod = importlib.import_module(f"docs_src.dependencies.{request.param}")
 
-client = TestClient(app)
+    client = TestClient(mod.app)
+    return client
 
 
 @pytest.mark.parametrize(
@@ -17,13 +34,13 @@ client = TestClient(app)
         ("/users", 200, {"q": None, "skip": 0, "limit": 100}),
     ],
 )
-def test_get(path, expected_status, expected_response):
+def test_get(path, expected_status, expected_response, client: TestClient):
     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, response.text
     assert response.json() == {
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial001_an.py b/tests/test_tutorial/test_dependencies/test_tutorial001_an.py
deleted file mode 100644 (file)
index 79c2a1e..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from docs_src.dependencies.tutorial001_an import app
-
-client = TestClient(app)
-
-
-@pytest.mark.parametrize(
-    "path,expected_status,expected_response",
-    [
-        ("/items", 200, {"q": None, "skip": 0, "limit": 100}),
-        ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}),
-        ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}),
-        ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}),
-        ("/users", 200, {"q": None, "skip": 0, "limit": 100}),
-    ],
-)
-def test_get(path, expected_status, expected_response):
-    response = client.get(path)
-    assert response.status_code == expected_status
-    assert response.json() == expected_response
-
-
-def test_openapi_schema():
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            },
-            "/users/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Users",
-                    "operationId": "read_users_users__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            },
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial001_an_py310.py b/tests/test_tutorial/test_dependencies/test_tutorial001_an_py310.py
deleted file mode 100644 (file)
index 7db55a1..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py310
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial001_an_py310 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py310
-@pytest.mark.parametrize(
-    "path,expected_status,expected_response",
-    [
-        ("/items", 200, {"q": None, "skip": 0, "limit": 100}),
-        ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}),
-        ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}),
-        ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}),
-        ("/users", 200, {"q": None, "skip": 0, "limit": 100}),
-    ],
-)
-def test_get(path, expected_status, expected_response, client: TestClient):
-    response = client.get(path)
-    assert response.status_code == expected_status
-    assert response.json() == expected_response
-
-
-@needs_py310
-def test_openapi_schema(client: TestClient):
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            },
-            "/users/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Users",
-                    "operationId": "read_users_users__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            },
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial001_an_py39.py b/tests/test_tutorial/test_dependencies/test_tutorial001_an_py39.py
deleted file mode 100644 (file)
index 68c2ded..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py39
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial001_an_py39 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py39
-@pytest.mark.parametrize(
-    "path,expected_status,expected_response",
-    [
-        ("/items", 200, {"q": None, "skip": 0, "limit": 100}),
-        ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}),
-        ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}),
-        ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}),
-        ("/users", 200, {"q": None, "skip": 0, "limit": 100}),
-    ],
-)
-def test_get(path, expected_status, expected_response, client: TestClient):
-    response = client.get(path)
-    assert response.status_code == expected_status
-    assert response.json() == expected_response
-
-
-@needs_py39
-def test_openapi_schema(client: TestClient):
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            },
-            "/users/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Users",
-                    "operationId": "read_users_users__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            },
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial001_py310.py b/tests/test_tutorial/test_dependencies/test_tutorial001_py310.py
deleted file mode 100644 (file)
index 381eecb..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py310
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial001_py310 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py310
-@pytest.mark.parametrize(
-    "path,expected_status,expected_response",
-    [
-        ("/items", 200, {"q": None, "skip": 0, "limit": 100}),
-        ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}),
-        ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}),
-        ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}),
-        ("/users", 200, {"q": None, "skip": 0, "limit": 100}),
-    ],
-)
-def test_get(path, expected_status, expected_response, client: TestClient):
-    response = client.get(path)
-    assert response.status_code == expected_status
-    assert response.json() == expected_response
-
-
-@needs_py310
-def test_openapi_schema(client: TestClient):
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            },
-            "/users/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Users",
-                    "operationId": "read_users_users__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            },
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
index 5c5d34cfcc6df28945922ab9755bb0035314142a..8221c83d44a970da0ef4307060c274fef446565a 100644 (file)
@@ -1,10 +1,27 @@
+import importlib
+
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
 
-from docs_src.dependencies.tutorial004 import app
+from ...utils import needs_py39, needs_py310
+
+
+@pytest.fixture(
+    name="client",
+    params=[
+        "tutorial004",
+        pytest.param("tutorial004_py310", marks=needs_py310),
+        "tutorial004_an",
+        pytest.param("tutorial004_an_py39", marks=needs_py39),
+        pytest.param("tutorial004_an_py310", marks=needs_py310),
+    ],
+)
+def get_client(request: pytest.FixtureRequest):
+    mod = importlib.import_module(f"docs_src.dependencies.{request.param}")
 
-client = TestClient(app)
+    client = TestClient(mod.app)
+    return client
 
 
 @pytest.mark.parametrize(
@@ -55,13 +72,13 @@ client = TestClient(app)
         ),
     ],
 )
-def test_get(path, expected_status, expected_response):
+def test_get(path, expected_status, expected_response, client: TestClient):
     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, response.text
     assert response.json() == {
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial004_an.py b/tests/test_tutorial/test_dependencies/test_tutorial004_an.py
deleted file mode 100644 (file)
index c5c1a1f..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from docs_src.dependencies.tutorial004_an import app
-
-client = TestClient(app)
-
-
-@pytest.mark.parametrize(
-    "path,expected_status,expected_response",
-    [
-        (
-            "/items",
-            200,
-            {
-                "items": [
-                    {"item_name": "Foo"},
-                    {"item_name": "Bar"},
-                    {"item_name": "Baz"},
-                ]
-            },
-        ),
-        (
-            "/items?q=foo",
-            200,
-            {
-                "items": [
-                    {"item_name": "Foo"},
-                    {"item_name": "Bar"},
-                    {"item_name": "Baz"},
-                ],
-                "q": "foo",
-            },
-        ),
-        (
-            "/items?q=foo&skip=1",
-            200,
-            {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"},
-        ),
-        (
-            "/items?q=bar&limit=2",
-            200,
-            {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"},
-        ),
-        (
-            "/items?q=bar&skip=1&limit=1",
-            200,
-            {"items": [{"item_name": "Bar"}], "q": "bar"},
-        ),
-        (
-            "/items?limit=1&q=bar&skip=1",
-            200,
-            {"items": [{"item_name": "Bar"}], "q": "bar"},
-        ),
-    ],
-)
-def test_get(path, expected_status, expected_response):
-    response = client.get(path)
-    assert response.status_code == expected_status
-    assert response.json() == expected_response
-
-
-def test_openapi_schema():
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            }
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial004_an_py310.py b/tests/test_tutorial/test_dependencies/test_tutorial004_an_py310.py
deleted file mode 100644 (file)
index 6fd093d..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py310
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial004_an_py310 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py310
-@pytest.mark.parametrize(
-    "path,expected_status,expected_response",
-    [
-        (
-            "/items",
-            200,
-            {
-                "items": [
-                    {"item_name": "Foo"},
-                    {"item_name": "Bar"},
-                    {"item_name": "Baz"},
-                ]
-            },
-        ),
-        (
-            "/items?q=foo",
-            200,
-            {
-                "items": [
-                    {"item_name": "Foo"},
-                    {"item_name": "Bar"},
-                    {"item_name": "Baz"},
-                ],
-                "q": "foo",
-            },
-        ),
-        (
-            "/items?q=foo&skip=1",
-            200,
-            {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"},
-        ),
-        (
-            "/items?q=bar&limit=2",
-            200,
-            {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"},
-        ),
-        (
-            "/items?q=bar&skip=1&limit=1",
-            200,
-            {"items": [{"item_name": "Bar"}], "q": "bar"},
-        ),
-        (
-            "/items?limit=1&q=bar&skip=1",
-            200,
-            {"items": [{"item_name": "Bar"}], "q": "bar"},
-        ),
-    ],
-)
-def test_get(path, expected_status, expected_response, client: TestClient):
-    response = client.get(path)
-    assert response.status_code == expected_status
-    assert response.json() == expected_response
-
-
-@needs_py310
-def test_openapi_schema(client: TestClient):
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            }
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial004_an_py39.py b/tests/test_tutorial/test_dependencies/test_tutorial004_an_py39.py
deleted file mode 100644 (file)
index fbbe84c..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py39
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial004_an_py39 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py39
-@pytest.mark.parametrize(
-    "path,expected_status,expected_response",
-    [
-        (
-            "/items",
-            200,
-            {
-                "items": [
-                    {"item_name": "Foo"},
-                    {"item_name": "Bar"},
-                    {"item_name": "Baz"},
-                ]
-            },
-        ),
-        (
-            "/items?q=foo",
-            200,
-            {
-                "items": [
-                    {"item_name": "Foo"},
-                    {"item_name": "Bar"},
-                    {"item_name": "Baz"},
-                ],
-                "q": "foo",
-            },
-        ),
-        (
-            "/items?q=foo&skip=1",
-            200,
-            {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"},
-        ),
-        (
-            "/items?q=bar&limit=2",
-            200,
-            {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"},
-        ),
-        (
-            "/items?q=bar&skip=1&limit=1",
-            200,
-            {"items": [{"item_name": "Bar"}], "q": "bar"},
-        ),
-        (
-            "/items?limit=1&q=bar&skip=1",
-            200,
-            {"items": [{"item_name": "Bar"}], "q": "bar"},
-        ),
-    ],
-)
-def test_get(path, expected_status, expected_response, client: TestClient):
-    response = client.get(path)
-    assert response.status_code == expected_status
-    assert response.json() == expected_response
-
-
-@needs_py39
-def test_openapi_schema(client: TestClient):
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            }
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial004_py310.py b/tests/test_tutorial/test_dependencies/test_tutorial004_py310.py
deleted file mode 100644 (file)
index 845b098..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py310
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial004_py310 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py310
-@pytest.mark.parametrize(
-    "path,expected_status,expected_response",
-    [
-        (
-            "/items",
-            200,
-            {
-                "items": [
-                    {"item_name": "Foo"},
-                    {"item_name": "Bar"},
-                    {"item_name": "Baz"},
-                ]
-            },
-        ),
-        (
-            "/items?q=foo",
-            200,
-            {
-                "items": [
-                    {"item_name": "Foo"},
-                    {"item_name": "Bar"},
-                    {"item_name": "Baz"},
-                ],
-                "q": "foo",
-            },
-        ),
-        (
-            "/items?q=foo&skip=1",
-            200,
-            {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"},
-        ),
-        (
-            "/items?q=bar&limit=2",
-            200,
-            {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"},
-        ),
-        (
-            "/items?q=bar&skip=1&limit=1",
-            200,
-            {"items": [{"item_name": "Bar"}], "q": "bar"},
-        ),
-        (
-            "/items?limit=1&q=bar&skip=1",
-            200,
-            {"items": [{"item_name": "Bar"}], "q": "bar"},
-        ),
-    ],
-)
-def test_get(path, expected_status, expected_response, client: TestClient):
-    response = client.get(path)
-    assert response.status_code == expected_status
-    assert response.json() == expected_response
-
-
-@needs_py310
-def test_openapi_schema(client: TestClient):
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": False,
-                            "schema": IsDict(
-                                {
-                                    "anyOf": [{"type": "string"}, {"type": "null"}],
-                                    "title": "Q",
-                                }
-                            )
-                            | IsDict(
-                                # TODO: remove when deprecating Pydantic v1
-                                {"title": "Q", "type": "string"}
-                            ),
-                            "name": "q",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Skip",
-                                "type": "integer",
-                                "default": 0,
-                            },
-                            "name": "skip",
-                            "in": "query",
-                        },
-                        {
-                            "required": False,
-                            "schema": {
-                                "title": "Limit",
-                                "type": "integer",
-                                "default": 100,
-                            },
-                            "name": "limit",
-                            "in": "query",
-                        },
-                    ],
-                }
-            }
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
index 5f14d9a3baccc5ef2c492ff4c0976b034aba10ad..4530762f763e3e6128bcacd8ad466778fe7d56a0 100644 (file)
@@ -1,12 +1,28 @@
+import importlib
+
+import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
 
-from docs_src.dependencies.tutorial006 import app
+from ...utils import needs_py39
+
+
+@pytest.fixture(
+    name="client",
+    params=[
+        "tutorial006",
+        "tutorial006_an",
+        pytest.param("tutorial006_an_py39", marks=needs_py39),
+    ],
+)
+def get_client(request: pytest.FixtureRequest):
+    mod = importlib.import_module(f"docs_src.dependencies.{request.param}")
 
-client = TestClient(app)
+    client = TestClient(mod.app)
+    return client
 
 
-def test_get_no_headers():
+def test_get_no_headers(client: TestClient):
     response = client.get("/items/")
     assert response.status_code == 422, response.text
     assert response.json() == IsDict(
@@ -45,13 +61,13 @@ def test_get_no_headers():
     )
 
 
-def test_get_invalid_one_header():
+def test_get_invalid_one_header(client: TestClient):
     response = client.get("/items/", headers={"X-Token": "invalid"})
     assert response.status_code == 400, response.text
     assert response.json() == {"detail": "X-Token header invalid"}
 
 
-def test_get_invalid_second_header():
+def test_get_invalid_second_header(client: TestClient):
     response = client.get(
         "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}
     )
@@ -59,7 +75,7 @@ def test_get_invalid_second_header():
     assert response.json() == {"detail": "X-Key header invalid"}
 
 
-def test_get_valid_headers():
+def test_get_valid_headers(client: TestClient):
     response = client.get(
         "/items/",
         headers={
@@ -71,7 +87,7 @@ def test_get_valid_headers():
     assert response.json() == [{"item": "Foo"}, {"item": "Bar"}]
 
 
-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() == {
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial006_an.py b/tests/test_tutorial/test_dependencies/test_tutorial006_an.py
deleted file mode 100644 (file)
index a307ff8..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from docs_src.dependencies.tutorial006_an import app
-
-client = TestClient(app)
-
-
-def test_get_no_headers():
-    response = client.get("/items/")
-    assert response.status_code == 422, response.text
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-token"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-key"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-            ]
-        }
-    ) | IsDict(
-        # TODO: remove when deprecating Pydantic v1
-        {
-            "detail": [
-                {
-                    "loc": ["header", "x-token"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-                {
-                    "loc": ["header", "x-key"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-            ]
-        }
-    )
-
-
-def test_get_invalid_one_header():
-    response = client.get("/items/", headers={"X-Token": "invalid"})
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Token header invalid"}
-
-
-def test_get_invalid_second_header():
-    response = client.get(
-        "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}
-    )
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Key header invalid"}
-
-
-def test_get_valid_headers():
-    response = client.get(
-        "/items/",
-        headers={
-            "X-Token": "fake-super-secret-token",
-            "X-Key": "fake-super-secret-key",
-        },
-    )
-    assert response.status_code == 200, response.text
-    assert response.json() == [{"item": "Foo"}, {"item": "Bar"}]
-
-
-def test_openapi_schema():
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Token", "type": "string"},
-                            "name": "x-token",
-                            "in": "header",
-                        },
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Key", "type": "string"},
-                            "name": "x-key",
-                            "in": "header",
-                        },
-                    ],
-                }
-            }
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial006_an_py39.py b/tests/test_tutorial/test_dependencies/test_tutorial006_an_py39.py
deleted file mode 100644 (file)
index b41b153..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py39
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial006_an_py39 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py39
-def test_get_no_headers(client: TestClient):
-    response = client.get("/items/")
-    assert response.status_code == 422, response.text
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-token"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-key"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-            ]
-        }
-    ) | IsDict(
-        # TODO: remove when deprecating Pydantic v1
-        {
-            "detail": [
-                {
-                    "loc": ["header", "x-token"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-                {
-                    "loc": ["header", "x-key"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-            ]
-        }
-    )
-
-
-@needs_py39
-def test_get_invalid_one_header(client: TestClient):
-    response = client.get("/items/", headers={"X-Token": "invalid"})
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Token header invalid"}
-
-
-@needs_py39
-def test_get_invalid_second_header(client: TestClient):
-    response = client.get(
-        "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}
-    )
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Key header invalid"}
-
-
-@needs_py39
-def test_get_valid_headers(client: TestClient):
-    response = client.get(
-        "/items/",
-        headers={
-            "X-Token": "fake-super-secret-token",
-            "X-Key": "fake-super-secret-key",
-        },
-    )
-    assert response.status_code == 200, response.text
-    assert response.json() == [{"item": "Foo"}, {"item": "Bar"}]
-
-
-@needs_py39
-def test_openapi_schema(client: TestClient):
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Token", "type": "string"},
-                            "name": "x-token",
-                            "in": "header",
-                        },
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Key", "type": "string"},
-                            "name": "x-key",
-                            "in": "header",
-                        },
-                    ],
-                }
-            }
-        },
-        "components": {
-            "schemas": {
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-            }
-        },
-    }
index 86acba9e4ff959e7c45296fca7f83c0efba43590..4d70922657e1b567650cd44b7975d7342502c799 100644 (file)
@@ -1,23 +1,39 @@
+import importlib
+
+import pytest
 from fastapi.testclient import TestClient
 
-from docs_src.dependencies.tutorial008b import app
+from ...utils import needs_py39
+
+
+@pytest.fixture(
+    name="client",
+    params=[
+        "tutorial008b",
+        "tutorial008b_an",
+        pytest.param("tutorial008b_an_py39", marks=needs_py39),
+    ],
+)
+def get_client(request: pytest.FixtureRequest):
+    mod = importlib.import_module(f"docs_src.dependencies.{request.param}")
 
-client = TestClient(app)
+    client = TestClient(mod.app)
+    return client
 
 
-def test_get_no_item():
+def test_get_no_item(client: TestClient):
     response = client.get("/items/foo")
     assert response.status_code == 404, response.text
     assert response.json() == {"detail": "Item not found"}
 
 
-def test_owner_error():
+def test_owner_error(client: TestClient):
     response = client.get("/items/plumbus")
     assert response.status_code == 400, response.text
     assert response.json() == {"detail": "Owner error: Rick"}
 
 
-def test_get_item():
+def test_get_item(client: TestClient):
     response = client.get("/items/portal-gun")
     assert response.status_code == 200, response.text
     assert response.json() == {"description": "Gun to create portals", "owner": "Rick"}
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial008b_an.py b/tests/test_tutorial/test_dependencies/test_tutorial008b_an.py
deleted file mode 100644 (file)
index 7f51fc5..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-from fastapi.testclient import TestClient
-
-from docs_src.dependencies.tutorial008b_an import app
-
-client = TestClient(app)
-
-
-def test_get_no_item():
-    response = client.get("/items/foo")
-    assert response.status_code == 404, response.text
-    assert response.json() == {"detail": "Item not found"}
-
-
-def test_owner_error():
-    response = client.get("/items/plumbus")
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "Owner error: Rick"}
-
-
-def test_get_item():
-    response = client.get("/items/portal-gun")
-    assert response.status_code == 200, response.text
-    assert response.json() == {"description": "Gun to create portals", "owner": "Rick"}
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial008b_an_py39.py b/tests/test_tutorial/test_dependencies/test_tutorial008b_an_py39.py
deleted file mode 100644 (file)
index 7d24809..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-import pytest
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py39
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial008b_an_py39 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py39
-def test_get_no_item(client: TestClient):
-    response = client.get("/items/foo")
-    assert response.status_code == 404, response.text
-    assert response.json() == {"detail": "Item not found"}
-
-
-@needs_py39
-def test_owner_error(client: TestClient):
-    response = client.get("/items/plumbus")
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "Owner error: Rick"}
-
-
-@needs_py39
-def test_get_item(client: TestClient):
-    response = client.get("/items/portal-gun")
-    assert response.status_code == 200, response.text
-    assert response.json() == {"description": "Gun to create portals", "owner": "Rick"}
index 27be8895a94963a56d19bc1305f52dcfe419bbca..11e96bf46f6cbd53dfab7cdd6c512184bd1ea83c 100644 (file)
@@ -1,38 +1,50 @@
+import importlib
+from types import ModuleType
+
 import pytest
 from fastapi.exceptions import FastAPIError
 from fastapi.testclient import TestClient
 
+from ...utils import needs_py39
+
 
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial008c import app
+@pytest.fixture(
+    name="mod",
+    params=[
+        "tutorial008c",
+        "tutorial008c_an",
+        pytest.param("tutorial008c_an_py39", marks=needs_py39),
+    ],
+)
+def get_mod(request: pytest.FixtureRequest):
+    mod = importlib.import_module(f"docs_src.dependencies.{request.param}")
 
-    client = TestClient(app)
-    return client
+    return mod
 
 
-def test_get_no_item(client: TestClient):
+def test_get_no_item(mod: ModuleType):
+    client = TestClient(mod.app)
     response = client.get("/items/foo")
     assert response.status_code == 404, response.text
     assert response.json() == {"detail": "Item not found, there's only a plumbus here"}
 
 
-def test_get(client: TestClient):
+def test_get(mod: ModuleType):
+    client = TestClient(mod.app)
     response = client.get("/items/plumbus")
     assert response.status_code == 200, response.text
     assert response.json() == "plumbus"
 
 
-def test_fastapi_error(client: TestClient):
+def test_fastapi_error(mod: ModuleType):
+    client = TestClient(mod.app)
     with pytest.raises(FastAPIError) as exc_info:
         client.get("/items/portal-gun")
     assert "No response object was returned" in exc_info.value.args[0]
 
 
-def test_internal_server_error():
-    from docs_src.dependencies.tutorial008c import app
-
-    client = TestClient(app, raise_server_exceptions=False)
+def test_internal_server_error(mod: ModuleType):
+    client = TestClient(mod.app, raise_server_exceptions=False)
     response = client.get("/items/portal-gun")
     assert response.status_code == 500, response.text
     assert response.text == "Internal Server Error"
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial008c_an.py b/tests/test_tutorial/test_dependencies/test_tutorial008c_an.py
deleted file mode 100644 (file)
index 10fa1ab..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-import pytest
-from fastapi.exceptions import FastAPIError
-from fastapi.testclient import TestClient
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial008c_an import app
-
-    client = TestClient(app)
-    return client
-
-
-def test_get_no_item(client: TestClient):
-    response = client.get("/items/foo")
-    assert response.status_code == 404, response.text
-    assert response.json() == {"detail": "Item not found, there's only a plumbus here"}
-
-
-def test_get(client: TestClient):
-    response = client.get("/items/plumbus")
-    assert response.status_code == 200, response.text
-    assert response.json() == "plumbus"
-
-
-def test_fastapi_error(client: TestClient):
-    with pytest.raises(FastAPIError) as exc_info:
-        client.get("/items/portal-gun")
-    assert "No response object was returned" in exc_info.value.args[0]
-
-
-def test_internal_server_error():
-    from docs_src.dependencies.tutorial008c_an import app
-
-    client = TestClient(app, raise_server_exceptions=False)
-    response = client.get("/items/portal-gun")
-    assert response.status_code == 500, response.text
-    assert response.text == "Internal Server Error"
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial008c_an_py39.py b/tests/test_tutorial/test_dependencies/test_tutorial008c_an_py39.py
deleted file mode 100644 (file)
index 6c3acff..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-import pytest
-from fastapi.exceptions import FastAPIError
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py39
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial008c_an_py39 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py39
-def test_get_no_item(client: TestClient):
-    response = client.get("/items/foo")
-    assert response.status_code == 404, response.text
-    assert response.json() == {"detail": "Item not found, there's only a plumbus here"}
-
-
-@needs_py39
-def test_get(client: TestClient):
-    response = client.get("/items/plumbus")
-    assert response.status_code == 200, response.text
-    assert response.json() == "plumbus"
-
-
-@needs_py39
-def test_fastapi_error(client: TestClient):
-    with pytest.raises(FastAPIError) as exc_info:
-        client.get("/items/portal-gun")
-    assert "No response object was returned" in exc_info.value.args[0]
-
-
-@needs_py39
-def test_internal_server_error():
-    from docs_src.dependencies.tutorial008c_an_py39 import app
-
-    client = TestClient(app, raise_server_exceptions=False)
-    response = client.get("/items/portal-gun")
-    assert response.status_code == 500, response.text
-    assert response.text == "Internal Server Error"
index 0434961123eeee47baa76660f34edb621975a0fb..bc99bb383507e9dcaca03301438b82ab552891b9 100644 (file)
@@ -1,41 +1,51 @@
+import importlib
+from types import ModuleType
+
 import pytest
 from fastapi.testclient import TestClient
 
+from ...utils import needs_py39
+
 
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial008d import app
+@pytest.fixture(
+    name="mod",
+    params=[
+        "tutorial008d",
+        "tutorial008d_an",
+        pytest.param("tutorial008d_an_py39", marks=needs_py39),
+    ],
+)
+def get_mod(request: pytest.FixtureRequest):
+    mod = importlib.import_module(f"docs_src.dependencies.{request.param}")
 
-    client = TestClient(app)
-    return client
+    return mod
 
 
-def test_get_no_item(client: TestClient):
+def test_get_no_item(mod: ModuleType):
+    client = TestClient(mod.app)
     response = client.get("/items/foo")
     assert response.status_code == 404, response.text
     assert response.json() == {"detail": "Item not found, there's only a plumbus here"}
 
 
-def test_get(client: TestClient):
+def test_get(mod: ModuleType):
+    client = TestClient(mod.app)
     response = client.get("/items/plumbus")
     assert response.status_code == 200, response.text
     assert response.json() == "plumbus"
 
 
-def test_internal_error(client: TestClient):
-    from docs_src.dependencies.tutorial008d import InternalError
-
-    with pytest.raises(InternalError) as exc_info:
+def test_internal_error(mod: ModuleType):
+    client = TestClient(mod.app)
+    with pytest.raises(mod.InternalError) as exc_info:
         client.get("/items/portal-gun")
     assert (
         exc_info.value.args[0] == "The portal gun is too dangerous to be owned by Rick"
     )
 
 
-def test_internal_server_error():
-    from docs_src.dependencies.tutorial008d import app
-
-    client = TestClient(app, raise_server_exceptions=False)
+def test_internal_server_error(mod: ModuleType):
+    client = TestClient(mod.app, raise_server_exceptions=False)
     response = client.get("/items/portal-gun")
     assert response.status_code == 500, response.text
     assert response.text == "Internal Server Error"
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial008d_an.py b/tests/test_tutorial/test_dependencies/test_tutorial008d_an.py
deleted file mode 100644 (file)
index f29d8cd..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-import pytest
-from fastapi.testclient import TestClient
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial008d_an import app
-
-    client = TestClient(app)
-    return client
-
-
-def test_get_no_item(client: TestClient):
-    response = client.get("/items/foo")
-    assert response.status_code == 404, response.text
-    assert response.json() == {"detail": "Item not found, there's only a plumbus here"}
-
-
-def test_get(client: TestClient):
-    response = client.get("/items/plumbus")
-    assert response.status_code == 200, response.text
-    assert response.json() == "plumbus"
-
-
-def test_internal_error(client: TestClient):
-    from docs_src.dependencies.tutorial008d_an import InternalError
-
-    with pytest.raises(InternalError) as exc_info:
-        client.get("/items/portal-gun")
-    assert (
-        exc_info.value.args[0] == "The portal gun is too dangerous to be owned by Rick"
-    )
-
-
-def test_internal_server_error():
-    from docs_src.dependencies.tutorial008d_an import app
-
-    client = TestClient(app, raise_server_exceptions=False)
-    response = client.get("/items/portal-gun")
-    assert response.status_code == 500, response.text
-    assert response.text == "Internal Server Error"
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial008d_an_py39.py b/tests/test_tutorial/test_dependencies/test_tutorial008d_an_py39.py
deleted file mode 100644 (file)
index 0a585f4..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-import pytest
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py39
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial008d_an_py39 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py39
-def test_get_no_item(client: TestClient):
-    response = client.get("/items/foo")
-    assert response.status_code == 404, response.text
-    assert response.json() == {"detail": "Item not found, there's only a plumbus here"}
-
-
-@needs_py39
-def test_get(client: TestClient):
-    response = client.get("/items/plumbus")
-    assert response.status_code == 200, response.text
-    assert response.json() == "plumbus"
-
-
-@needs_py39
-def test_internal_error(client: TestClient):
-    from docs_src.dependencies.tutorial008d_an_py39 import InternalError
-
-    with pytest.raises(InternalError) as exc_info:
-        client.get("/items/portal-gun")
-    assert (
-        exc_info.value.args[0] == "The portal gun is too dangerous to be owned by Rick"
-    )
-
-
-@needs_py39
-def test_internal_server_error():
-    from docs_src.dependencies.tutorial008d_an_py39 import app
-
-    client = TestClient(app, raise_server_exceptions=False)
-    response = client.get("/items/portal-gun")
-    assert response.status_code == 500, response.text
-    assert response.text == "Internal Server Error"
index 6b53c83bb5cca8c858e3d36e3a54c47bf14b2f29..0af17e9bc57ddf797ec161e83270c046241e2272 100644 (file)
@@ -1,12 +1,28 @@
+import importlib
+
+import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
 
-from docs_src.dependencies.tutorial012 import app
+from ...utils import needs_py39
+
+
+@pytest.fixture(
+    name="client",
+    params=[
+        "tutorial012",
+        "tutorial012_an",
+        pytest.param("tutorial012_an_py39", marks=needs_py39),
+    ],
+)
+def get_client(request: pytest.FixtureRequest):
+    mod = importlib.import_module(f"docs_src.dependencies.{request.param}")
 
-client = TestClient(app)
+    client = TestClient(mod.app)
+    return client
 
 
-def test_get_no_headers_items():
+def test_get_no_headers_items(client: TestClient):
     response = client.get("/items/")
     assert response.status_code == 422, response.text
     assert response.json() == IsDict(
@@ -45,7 +61,7 @@ def test_get_no_headers_items():
     )
 
 
-def test_get_no_headers_users():
+def test_get_no_headers_users(client: TestClient):
     response = client.get("/users/")
     assert response.status_code == 422, response.text
     assert response.json() == IsDict(
@@ -84,19 +100,19 @@ def test_get_no_headers_users():
     )
 
 
-def test_get_invalid_one_header_items():
+def test_get_invalid_one_header_items(client: TestClient):
     response = client.get("/items/", headers={"X-Token": "invalid"})
     assert response.status_code == 400, response.text
     assert response.json() == {"detail": "X-Token header invalid"}
 
 
-def test_get_invalid_one_users():
+def test_get_invalid_one_users(client: TestClient):
     response = client.get("/users/", headers={"X-Token": "invalid"})
     assert response.status_code == 400, response.text
     assert response.json() == {"detail": "X-Token header invalid"}
 
 
-def test_get_invalid_second_header_items():
+def test_get_invalid_second_header_items(client: TestClient):
     response = client.get(
         "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}
     )
@@ -104,7 +120,7 @@ def test_get_invalid_second_header_items():
     assert response.json() == {"detail": "X-Key header invalid"}
 
 
-def test_get_invalid_second_header_users():
+def test_get_invalid_second_header_users(client: TestClient):
     response = client.get(
         "/users/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}
     )
@@ -112,7 +128,7 @@ def test_get_invalid_second_header_users():
     assert response.json() == {"detail": "X-Key header invalid"}
 
 
-def test_get_valid_headers_items():
+def test_get_valid_headers_items(client: TestClient):
     response = client.get(
         "/items/",
         headers={
@@ -124,7 +140,7 @@ def test_get_valid_headers_items():
     assert response.json() == [{"item": "Portal Gun"}, {"item": "Plumbus"}]
 
 
-def test_get_valid_headers_users():
+def test_get_valid_headers_users(client: TestClient):
     response = client.get(
         "/users/",
         headers={
@@ -136,7 +152,7 @@ def test_get_valid_headers_users():
     assert response.json() == [{"username": "Rick"}, {"username": "Morty"}]
 
 
-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() == {
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial012_an.py b/tests/test_tutorial/test_dependencies/test_tutorial012_an.py
deleted file mode 100644 (file)
index 75adb69..0000000
+++ /dev/null
@@ -1,250 +0,0 @@
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from docs_src.dependencies.tutorial012_an import app
-
-client = TestClient(app)
-
-
-def test_get_no_headers_items():
-    response = client.get("/items/")
-    assert response.status_code == 422, response.text
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-token"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-key"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-            ]
-        }
-    ) | IsDict(
-        # TODO: remove when deprecating Pydantic v1
-        {
-            "detail": [
-                {
-                    "loc": ["header", "x-token"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-                {
-                    "loc": ["header", "x-key"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-            ]
-        }
-    )
-
-
-def test_get_no_headers_users():
-    response = client.get("/users/")
-    assert response.status_code == 422, response.text
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-token"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-key"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-            ]
-        }
-    ) | IsDict(
-        # TODO: remove when deprecating Pydantic v1
-        {
-            "detail": [
-                {
-                    "loc": ["header", "x-token"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-                {
-                    "loc": ["header", "x-key"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-            ]
-        }
-    )
-
-
-def test_get_invalid_one_header_items():
-    response = client.get("/items/", headers={"X-Token": "invalid"})
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Token header invalid"}
-
-
-def test_get_invalid_one_users():
-    response = client.get("/users/", headers={"X-Token": "invalid"})
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Token header invalid"}
-
-
-def test_get_invalid_second_header_items():
-    response = client.get(
-        "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}
-    )
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Key header invalid"}
-
-
-def test_get_invalid_second_header_users():
-    response = client.get(
-        "/users/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}
-    )
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Key header invalid"}
-
-
-def test_get_valid_headers_items():
-    response = client.get(
-        "/items/",
-        headers={
-            "X-Token": "fake-super-secret-token",
-            "X-Key": "fake-super-secret-key",
-        },
-    )
-    assert response.status_code == 200, response.text
-    assert response.json() == [{"item": "Portal Gun"}, {"item": "Plumbus"}]
-
-
-def test_get_valid_headers_users():
-    response = client.get(
-        "/users/",
-        headers={
-            "X-Token": "fake-super-secret-token",
-            "X-Key": "fake-super-secret-key",
-        },
-    )
-    assert response.status_code == 200, response.text
-    assert response.json() == [{"username": "Rick"}, {"username": "Morty"}]
-
-
-def test_openapi_schema():
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Token", "type": "string"},
-                            "name": "x-token",
-                            "in": "header",
-                        },
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Key", "type": "string"},
-                            "name": "x-key",
-                            "in": "header",
-                        },
-                    ],
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                }
-            },
-            "/users/": {
-                "get": {
-                    "summary": "Read Users",
-                    "operationId": "read_users_users__get",
-                    "parameters": [
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Token", "type": "string"},
-                            "name": "x-token",
-                            "in": "header",
-                        },
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Key", "type": "string"},
-                            "name": "x-key",
-                            "in": "header",
-                        },
-                    ],
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                }
-            },
-        },
-        "components": {
-            "schemas": {
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-            }
-        },
-    }
diff --git a/tests/test_tutorial/test_dependencies/test_tutorial012_an_py39.py b/tests/test_tutorial/test_dependencies/test_tutorial012_an_py39.py
deleted file mode 100644 (file)
index e0a3d1e..0000000
+++ /dev/null
@@ -1,266 +0,0 @@
-import pytest
-from dirty_equals import IsDict
-from fastapi.testclient import TestClient
-
-from ...utils import needs_py39
-
-
-@pytest.fixture(name="client")
-def get_client():
-    from docs_src.dependencies.tutorial012_an_py39 import app
-
-    client = TestClient(app)
-    return client
-
-
-@needs_py39
-def test_get_no_headers_items(client: TestClient):
-    response = client.get("/items/")
-    assert response.status_code == 422, response.text
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-token"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-key"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-            ]
-        }
-    ) | IsDict(
-        # TODO: remove when deprecating Pydantic v1
-        {
-            "detail": [
-                {
-                    "loc": ["header", "x-token"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-                {
-                    "loc": ["header", "x-key"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-            ]
-        }
-    )
-
-
-@needs_py39
-def test_get_no_headers_users(client: TestClient):
-    response = client.get("/users/")
-    assert response.status_code == 422, response.text
-    assert response.json() == IsDict(
-        {
-            "detail": [
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-token"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-                {
-                    "type": "missing",
-                    "loc": ["header", "x-key"],
-                    "msg": "Field required",
-                    "input": None,
-                },
-            ]
-        }
-    ) | IsDict(
-        # TODO: remove when deprecating Pydantic v1
-        {
-            "detail": [
-                {
-                    "loc": ["header", "x-token"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-                {
-                    "loc": ["header", "x-key"],
-                    "msg": "field required",
-                    "type": "value_error.missing",
-                },
-            ]
-        }
-    )
-
-
-@needs_py39
-def test_get_invalid_one_header_items(client: TestClient):
-    response = client.get("/items/", headers={"X-Token": "invalid"})
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Token header invalid"}
-
-
-@needs_py39
-def test_get_invalid_one_users(client: TestClient):
-    response = client.get("/users/", headers={"X-Token": "invalid"})
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Token header invalid"}
-
-
-@needs_py39
-def test_get_invalid_second_header_items(client: TestClient):
-    response = client.get(
-        "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}
-    )
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Key header invalid"}
-
-
-@needs_py39
-def test_get_invalid_second_header_users(client: TestClient):
-    response = client.get(
-        "/users/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"}
-    )
-    assert response.status_code == 400, response.text
-    assert response.json() == {"detail": "X-Key header invalid"}
-
-
-@needs_py39
-def test_get_valid_headers_items(client: TestClient):
-    response = client.get(
-        "/items/",
-        headers={
-            "X-Token": "fake-super-secret-token",
-            "X-Key": "fake-super-secret-key",
-        },
-    )
-    assert response.status_code == 200, response.text
-    assert response.json() == [{"item": "Portal Gun"}, {"item": "Plumbus"}]
-
-
-@needs_py39
-def test_get_valid_headers_users(client: TestClient):
-    response = client.get(
-        "/users/",
-        headers={
-            "X-Token": "fake-super-secret-token",
-            "X-Key": "fake-super-secret-key",
-        },
-    )
-    assert response.status_code == 200, response.text
-    assert response.json() == [{"username": "Rick"}, {"username": "Morty"}]
-
-
-@needs_py39
-def test_openapi_schema(client: TestClient):
-    response = client.get("/openapi.json")
-    assert response.status_code == 200, response.text
-    assert response.json() == {
-        "openapi": "3.1.0",
-        "info": {"title": "FastAPI", "version": "0.1.0"},
-        "paths": {
-            "/items/": {
-                "get": {
-                    "summary": "Read Items",
-                    "operationId": "read_items_items__get",
-                    "parameters": [
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Token", "type": "string"},
-                            "name": "x-token",
-                            "in": "header",
-                        },
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Key", "type": "string"},
-                            "name": "x-key",
-                            "in": "header",
-                        },
-                    ],
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                }
-            },
-            "/users/": {
-                "get": {
-                    "summary": "Read Users",
-                    "operationId": "read_users_users__get",
-                    "parameters": [
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Token", "type": "string"},
-                            "name": "x-token",
-                            "in": "header",
-                        },
-                        {
-                            "required": True,
-                            "schema": {"title": "X-Key", "type": "string"},
-                            "name": "x-key",
-                            "in": "header",
-                        },
-                    ],
-                    "responses": {
-                        "200": {
-                            "description": "Successful Response",
-                            "content": {"application/json": {"schema": {}}},
-                        },
-                        "422": {
-                            "description": "Validation Error",
-                            "content": {
-                                "application/json": {
-                                    "schema": {
-                                        "$ref": "#/components/schemas/HTTPValidationError"
-                                    }
-                                }
-                            },
-                        },
-                    },
-                }
-            },
-        },
-        "components": {
-            "schemas": {
-                "HTTPValidationError": {
-                    "title": "HTTPValidationError",
-                    "type": "object",
-                    "properties": {
-                        "detail": {
-                            "title": "Detail",
-                            "type": "array",
-                            "items": {"$ref": "#/components/schemas/ValidationError"},
-                        }
-                    },
-                },
-                "ValidationError": {
-                    "title": "ValidationError",
-                    "required": ["loc", "msg", "type"],
-                    "type": "object",
-                    "properties": {
-                        "loc": {
-                            "title": "Location",
-                            "type": "array",
-                            "items": {
-                                "anyOf": [{"type": "string"}, {"type": "integer"}]
-                            },
-                        },
-                        "msg": {"title": "Message", "type": "string"},
-                        "type": {"title": "Error Type", "type": "string"},
-                    },
-                },
-            }
-        },
-    }