Skip to content

Commit 26c0291

Browse files
fix: handle Schemathesis 4.x FailureGroup exception properly (#21)
- Catch BaseExceptionGroup to handle FailureGroup from case.validate_response() - Extract individual validation failures from exception group - Create separate Discrepancy object for each validation failure - Keep fallback Exception handler for non-group exceptions - Update ruff and mypy target versions to py311 to match GitHub Actions - Fixes validation pipeline crash in Python 3.11+
1 parent bdb6198 commit 26c0291

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ f5xc-reconcile = "scripts.reconcile:main"
6464
f5xc-release = "scripts.release:main"
6565

6666
[tool.ruff]
67-
target-version = "py310"
67+
target-version = "py311"
6868
line-length = 100
6969

7070
[tool.ruff.lint]
@@ -87,7 +87,7 @@ addopts = "-v --tb=short"
8787
asyncio_mode = "auto"
8888

8989
[tool.mypy]
90-
python_version = "3.10"
90+
python_version = "3.11"
9191
warn_return_any = true
9292
warn_unused_configs = true
9393
ignore_missing_imports = true

scripts/utils/schemathesis_runner.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,24 @@ def _test_operation(self, operation: Any) -> SchemathesisResult:
231231
try:
232232
# Schemathesis 4.x validation
233233
case.validate_response(response)
234+
except BaseExceptionGroup as eg:
235+
# Schemathesis 4.x raises FailureGroup (exception group) for validation failures
236+
# Extract individual validation failures and create discrepancies
237+
for validation_error in eg.exceptions:
238+
discrepancy = Discrepancy(
239+
path=case.path,
240+
property_name="response_schema",
241+
constraint_type="schema_validation",
242+
discrepancy_type=DiscrepancyType.CONSTRAINT_MISMATCH,
243+
spec_value="Valid per OpenAPI schema",
244+
api_behavior=str(validation_error),
245+
test_values=[self._case_to_dict(case)],
246+
recommendation=f"Update schema or fix API response: {validation_error}",
247+
)
248+
result.discrepancies.append(discrepancy)
249+
result.status = TestStatus.FAILED
234250
except Exception as validation_error:
235-
# Schema validation failed - this is a discrepancy
251+
# Fallback for non-group exceptions
236252
discrepancy = Discrepancy(
237253
path=case.path,
238254
property_name="response_schema",

0 commit comments

Comments
 (0)