GuideBeginner

Test Failure Diagnosis

Learn to diagnose why a test fails — the skill no "how to write tests" guide covers. A red test is information, not an enemy: this guide teaches you the scientific method of debugging (hypothesis → experiment) applied to pytest failures, starting with reading a failure report without drowning (the traceback, assert-rewriting, `--showlocals`, `--tb=short/long/line`) and isolating a failure down to its minimal reproduction. From there you move into the interactive debugger with `pytest --pdb` and the core `pdb` commands, learn to diagnose flaky tests (that sometimes pass, sometimes don't) and tests with order dependence or shared state, and close with binary search: using `git bisect` to find exactly which commit broke a test. All the hands-on material is Reservo test suites with deliberately planted failures of different kinds, which you learn to diagnose one by one. The final project hands you a broken suite with several failures of different types and asks for a complete diagnosis log — symptom, hypothesis, experiment, cause, and fix — for each one.

64
lessons
8
modules
English · Spanish
available in
Yes
certificate
Free
access
NIEVA

Outcomes

What you'll be able to do

  • Adopt the right mindset when facing a failure: a red test is information, not a failure, and apply the scientific method (hypothesis → experiment) to debugging
  • Read a pytest failure report end to end: assert-rewriting, the bottom-up traceback, `--showlocals`, `--tb=short/long/line`, and distinguish where the failure IS from where it's REPORTED
  • Isolate and reproduce a failure minimally: run just the failing test (`-k`, nodeid), `--lf`/`--ff`, and strip away noise down to the minimal reproduction
  • Use the interactive debugger: `pytest --pdb` (post-mortem), `breakpoint()`/`--trace`, and the core `pdb` commands (`p`, `pp`, `l`, `w`, `n`, `s`, `c`) to inspect state at the exact point of failure
  • Diagnose flaky (non-deterministic) tests: their typical causes (clock, randomness, external resources, order) and how to reproduce them reliably
  • Detect order dependence and shared state between tests, including using `pytest-randomly` to expose it
  • Bisect a problem with binary search: use `git bisect` to find which commit broke a test, or manually bisect a large suite down to the culprit test
  • Diagnose and fix a suite with several planted failures of different types, delivering a full diagnosis log for each one

Before you start

What you need to bring

It's for you if...

  • Devs who already write tests but get stuck in front of a failure they don't understand, with no method to move forward
  • Teams tired of flaky tests that sometimes pass and sometimes don't, with no idea where to start diagnosing them
  • Devs who avoid the debugger and debug with scattered `print()` calls, wasting time on failures `pdb` would solve in minutes
  • Anyone who's gotten a "it broke in some commit from last week" and needs to find which one

Requirements and materials

  • Testing Fundamentals and TDD guide completed (or equivalent: writing and running tests with pytest)
  • Basic git knowledge (commits, log) for the bisection module
  • Python 3.14 and pytest 9.1.1 installed locally (`pdb` is part of the standard library)

Content

The syllabus, module by module

Open any of them to see its lessons.

Common questions

What people usually ask

Start whenever you like

Reviews

What students say

These reviews are from enrolled students who completed at least 50% of the course. We moderate reviews only on content grounds (spam, offensive language, personal data), never for being critical or negative.

No approved reviews yet.

Be the first to share your experience!