Python Developer interview question
What is your Python testing strategy?
Use fast unit tests for pure behaviour, integration tests for real boundaries, fixtures with narrow scope, and contract or end-to-end tests only for critical paths; isolate time, network, and mutable global state.
Direct answer
What a strong answer covers
How it works
A Python test suite is built around pytest fixtures with the narrowest scope that works, parametrised cases for input variations, and a clear split between fast tests that need nothing external and slower tests that hit a real database or HTTP server in a container. Time, randomness, network, and environment variables are injected or patched at the boundary so tests are deterministic. Coverage is a guide for finding untested branches, not a target, and the suite must stay fast enough to run on every commit.
Example
A payment module has pure unit tests for fee calculation with a parametrised table of twenty cases, integration tests that run the repository against PostgreSQL in Docker, and one end-to-end test that drives the API with httpx. freezegun pins the clock in tests that depend on billing dates, and responses stubs the card provider so no test reaches the network.
Common mistakes
- Patching so deep inside the module that the test passes while the real code path is broken.
- Sharing a session-scoped database fixture across tests that mutate it, so failures depend on order.
- Chasing 100 percent coverage with tests that assert nothing meaningful.
A useful answer structure
Answer from your own work.
Do not memorise a script: use only examples you can explain honestly in follow-up questions.
Open the desktop workspace and rehearse a clear answer in your own words.