PyCon GR 2025

To mock or not to mock? Choosing a mocking strategy for your unit tests
2025-08-30 , Auditorium "Miltiadis Evert"

We've all done it-written tests full of mocks that pass, but don't really prove anything.
Mocking is powerful, but using the wrong kind of mock (or mocking the wrong thing) leads to fragile tests and false confidence. Over-reliance on mocks can obscure a system's behaviour, making tests more flaky while hiding integration issues with other services. This talk is about using mocking intentionally, with a
clear purpose behind each approach,

I'll break down four common patterns:

  • Pure mocks for verifying behaviour

  • Stubs to simulate simple responses

  • Spies to track how something was used, without taking full control

  • Fakes to produce minimal but working versions of real systems like in-memory APIs
    or fake databases

Along the way, we'll explore how to implement these strategies using Python's most
popular testing frameworks. Whether you're testing micro-services, APIs, or just trying to write more trustworthy unit tests, this talk will help you choose the right approach for the job and avoid common pitfalls.

If you've ever wondered "am I mocking too much?" or "why does this test feel flaky even
though it passes?", this talk is for you. You'll walk away with better instincts for testing real-
world systems and a few solid patterns to keep your test suite fast, clear, and reliable.

I am a software engineer at JPMorgan, write mostly Back-End with experience in DevOps and occasional Front-End work. I enjoy diving deep into problems and debugging performance issues.