Q&A
What prompts work best for generating pytest tests from an OpenAPI spec?
Ajitesh MohantaAmbassador
2w ago 1,796 0
I have a FastAPI service with a well-maintained OpenAPI spec (auto-generated by FastAPI). I want to generate a meaningful first-pass pytest test suite from it using an LLM.
My current prompt approach: paste the full spec JSON + ask for tests. Result: tests that compile but assert nothing meaningful (just status code 200 on the happy path).
Better prompts I've tried:
- Specifying test categories (happy path, validation, auth, edge cases) explicitly
- Asking for one endpoint at a time with the schema pasted inline
- Including an example of a test I've already written
Anyone have a prompt structure that consistently produces tests with meaningful assertions, not just structural placeholders?