Skip to content
Preptima

Testing in Python interview questions

pytest fixtures and parametrisation, mocking and patching boundaries, and coverage honestly read.

3 questions in Python.

medium3

mediumConceptScenario

Your suite mocks the database, every test passes, and the release still broke. What should you have tested instead?

A mock encodes your belief about the collaborator, so asserting against it proves the code matches your belief rather than reality. Use autospec so signatures are checked, and put a small number of tests against the real engine at the boundary the mock replaced. Use this mocking answer to show the decision, trade-off, and evidence rather than a memorised definition.

5 minmid, senior, staff