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

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Apr 15 19:23:33 EDT 2008


"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.

Use the TestCase.setUp and TestCase.tearDown methods to handle any
fixtures needed by test cases in each class of test cases. That way,
the fixtures will be set up and torn down between every test case.
Find out about test fixtures in the documentation for unittest
<URLhttp://www.python.org/doc/lib/module-unittest>.

-- 
 \     "All my life I've had one dream: to achieve my many goals."  -- |
  `\                                             Homer, _The Simpsons_ |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list