Skip to content

Commit bd1abad

Browse files
authored
[python] fix uniqueItems validation tests (OpenAPITools#24092)
Pydantic 2 removed conlist(unique_items=True). The migration in 04fa53b kept OpenAPI arrays as lists because sets would lose ordering and complicate JSON serialization, but left the old validation tests in the synchronous and lazy-import samples. Those tests do not require an exception, so they normally pass after making a Petstore request and fail only when that request produces an unrelated response validation error. Remove them from the Pydantic 2 samples. Pydantic 1 still enforces uniqueItems. Make its test require the expected validation error so a regression cannot silently pass.
1 parent 4a5f3a7 commit bd1abad

3 files changed

Lines changed: 3 additions & 15 deletions

File tree

samples/openapi3/client/petstore/python-lazyImports/tests/test_api_validation.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ def setUpModels(self):
4040
self.pet.category = self.category
4141
self.pet.tags = [self.tag]
4242

43-
def test_set_param_validation(self):
44-
try:
45-
self.pet_api.find_pets_by_tags(["a", "a"])
46-
except ValidationError as e:
47-
self.assertTrue("the list has duplicated items" in str(e))
48-
4943
def test_required_param_validation(self):
5044
try:
5145
self.pet_api.get_pet_by_id() # type: ignore

samples/openapi3/client/petstore/python-pydantic-v1/tests/test_api_validation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def setUpModels(self):
4747
self.pet.tags = [self.tag]
4848

4949
def test_set_param_validation(self):
50-
try:
50+
with self.assertRaisesRegex(
51+
ValidationError, "the list has duplicated items"
52+
):
5153
self.pet_api.find_pets_by_tags(["a", "a"])
52-
except ValidationError as e:
53-
self.assertTrue("the list has duplicated items" in str(e))
5454

5555
def test_required_param_validation(self):
5656
try:

samples/openapi3/client/petstore/python/tests/test_api_validation.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ def setUpModels(self):
4040
self.pet.category = self.category
4141
self.pet.tags = [self.tag]
4242

43-
def test_set_param_validation(self):
44-
try:
45-
self.pet_api.find_pets_by_tags(["a", "a"])
46-
except ValidationError as e:
47-
self.assertTrue("the list has duplicated items" in str(e))
48-
4943
def test_required_param_validation(self):
5044
try:
5145
self.pet_api.get_pet_by_id() # type: ignore

0 commit comments

Comments
 (0)