You want contract tests for an internal REST API your scripts depend on. What do you do?
AdvancedScenarioTesting, CI/CD, packaging & services
Answer
Situation read → Your scripts break when the API changes shape.
What I'd do →
- Validate responses against the API's OpenAPI schema in a scheduled integration test (
jsonschemaorschemathesis). - Model responses with pydantic in the client, so shape changes fail loudly at the boundary.
- Record real responses as fixtures (sanitized) for unit tests with
responses. - Agree on versioning with the API team; consumer-driven contracts (Pact) if the relationship is critical.
Why → Boundary validation turns silent data bugs into clear errors.
Interview tip → Mention pydantic models as runtime contracts.
More on Testing, CI/CD, packaging & services
You join a team whose Python automation repo has no tests. Where do you start?BeginnerYour pytest suite takes 12 minutes. How do you speed it up?IntermediateA test passes locally but fails in CI only when run with the rest of the suite. What do you suspect?IntermediateYou want a reusable CI pipeline for 15 Python tool repos. What goes in it?IntermediateYour Python Docker image is 1.1 GB. How do you shrink it?IntermediateYou want to distribute an internal CLI to 200 engineers. What are your options?Intermediate