6 / 89 · 04 API & Contract Testing with AI · From OpenAPI Schema to Test Suite← prev⊞ allnext →☰ Read as one page
1.6Validation: Verifying Generated Tests
After generation, validate the test suite:
# 1. Syntax check: do all files parse?
import ast
for test_file in glob("tests/generated/*.py"):
ast.parse(open(test_file).read())
# 2. Import check: do all imports resolve?
pytest --collect-only tests/generated/
# 3. Execution check: do tests run (even if some fail)?
pytest tests/generated/ -v --tb=short
# 4. Coverage check: did we generate tests for all endpoints?
endpoints_in_schema = set(parse_all_endpoints(schema))
endpoints_tested = set(extract_endpoints_from_tests("tests/generated/"))
missing = endpoints_in_schema - endpoints_tested
if missing:
print(f"MISSING TESTS for: {missing}")