]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
✅ Fix a minor bug in the test `tests/test_modules_same_name_body/test_main.py` (...
authoralv2017 <v.alishauskaite@gmail.com>
Thu, 27 Feb 2025 14:42:41 +0000 (16:42 +0200)
committerGitHub <noreply@github.com>
Thu, 27 Feb 2025 14:42:41 +0000 (15:42 +0100)
tests/test_modules_same_name_body/test_main.py

index cc165bdcaa2589178ca590d2f76fffc8627df359..263d87df263229b59b0348bb76b1b78c633977e3 100644 (file)
@@ -1,3 +1,4 @@
+import pytest
 from fastapi.testclient import TestClient
 
 from .app.main import app
@@ -5,29 +6,22 @@ from .app.main import app
 client = TestClient(app)
 
 
-def test_post_a():
+@pytest.mark.parametrize(
+    "path", ["/a/compute", "/a/compute/", "/b/compute", "/b/compute/"]
+)
+def test_post(path):
     data = {"a": 2, "b": "foo"}
-    response = client.post("/a/compute", json=data)
+    response = client.post(path, json=data)
     assert response.status_code == 200, response.text
-    data = response.json()
+    assert data == response.json()
 
 
-def test_post_a_invalid():
+@pytest.mark.parametrize(
+    "path", ["/a/compute", "/a/compute/", "/b/compute", "/b/compute/"]
+)
+def test_post_invalid(path):
     data = {"a": "bar", "b": "foo"}
-    response = client.post("/a/compute", json=data)
-    assert response.status_code == 422, response.text
-
-
-def test_post_b():
-    data = {"a": 2, "b": "foo"}
-    response = client.post("/b/compute/", json=data)
-    assert response.status_code == 200, response.text
-    data = response.json()
-
-
-def test_post_b_invalid():
-    data = {"a": "bar", "b": "foo"}
-    response = client.post("/b/compute/", json=data)
+    response = client.post(path, json=data)
     assert response.status_code == 422, response.text