How to have unittest tests to be executed in the order they appear?

Matthew Woodcraft mattheww at chiark.greenend.org.uk
Wed Apr 16 17:31:52 EDT 2008


Ben Finney  <bignose+hates-spam at benfinney.id.au> wrote:
>"Giampaolo Rodola'" <gnewsg at gmail.com> writes:
>> Is there a way to force unittest to run test methods in the order
>> they appear?

> No, and this is a good thing.

> Your test cases should *not* depend on any state from other test
> cases; they should function equally well when executed in any
> arbitrary sequence. Dependencies between separate test cases (e.g.
> "they only work correctly when run in a specific sequence") means
> you're not isolating them properly.


So a mode to randomise the test sequence would be nice to have.

Unittest's behaviour (using alphabetical order) doesn't really help to
detect undesired dependencies (which might be bugs in the test suite or
bugs in the underlying code).

But running tests in the order they appear is often helpful: you can
put the tests for basic stuff before the tests for advanced stuff, and
then if you suddenly get seventeen failing tests, you know that the
first failure is the best bet to investigate first.

-M-




More information about the Python-list mailing list