The Failed Test: Debugging Automation Like a Senior · Lesson 1 of 6 · Bonus module

The Four Questions That Sort Any Failure

A red test is a claim, not a verdict. Four questions tell you which problem you actually have — before you touch any code.

By Shahriyar · Updated

Ask them in order

  1. Did it ever pass? Check git log on the test file. A test that was never green is a new-test problem, not a regression.
  2. Does it fail locally? CI-only failures are environment problems — lesson 5 covers those. Failing on your machine is good news: you can see it.
  3. Does it fail alone? Run just that one test. Passes alone but fails in the suite? Another test is leaking state into it.
  4. Does it fail every time? Run it ten times. 10/10 is a real bug — follow the trace. 3/10 is a race — timing is the suspect.
▸ The four questions as commands
# 1. did it ever pass?
git log --oneline -- tests/test_checkout.py

# 2 + 3. does it fail locally — alone, and in company?
pytest tests/test_checkout.py::test_guest_checkout
pytest tests/

# 4. does it fail every time?
for i in {1..10}; do pytest -q tests/test_checkout.py::test_guest_checkout; done

What the answers mean

Grounded in the pytest docs on selecting and re-running tests

All lessons in The Failed Test: Debugging Automation Like a Senior

  1. The Four Questions That Sort Any Failure
  2. Reading the Traceback Like a Senior
  3. Shrinking the Search Space
  4. Flaky or Broken: Prove It With a Number
  5. It Only Fails in CI
  6. The Write-Up: Product Bug or Test Bug