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

D'Arcy J.M. Cain darcy at druid.net
Tue Apr 15 15:14:39 EDT 2008


On Tue, 15 Apr 2008 12:02:48 -0700 (PDT)
"Giampaolo Rodola'" <gnewsg at gmail.com> wrote:
> Hi there.
> Is there a way to force unittest to run test methods in the order they
> appear?

Since they run in alphabetical order why not just rename them to the
order you want them to run?  Something like this:

  def test_010_z(self):
  def test_020_b(self):
  def test_030_d(self):

Note the numbering scheme that allows tests to be added between the
existing ones if necessary.

However, do consider writing your tests so that order is irrelevant.
If a test depends on a previous test running then it isn't a proprt
self-contained test.  For one thing, you can't run a single test that
way if you wanted to.

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list