Repaso
EspaƱol
TestingIntermediateTST-16

Why should tests not depend on execution order?

Options

  1. Test order is always alphabetical, so it is safe
  2. Order can change; hidden dependencies cause failures (Correct option)
  3. It makes the tests run slower than they should
  4. pytest forbids tests that rely on any order

Answer

Order can change (parallel runs, random ordering, running one test alone); hidden dependencies cause failures that are hard to reproduce

Why

If test B only passes because test A created some data first, then B fails when run alone, in parallel or in a different order.

Each test should create what it needs and clean up after itself.

Plugins like pytest-randomly shuffle the order to reveal hidden dependencies; pytest-xdist runs tests in parallel.

Remember

Every test must work alone, in any order.

Key terms

Practice this question in Repaso