[TIP] Tipp: Ordering Test Files

Eduardo Schettino schettino72 at gmail.com
Tue Oct 9 21:34:07 PDT 2018


On Wed, Oct 10, 2018 at 12:34 AM Ned Batchelder <ned at nedbatchelder.com>
wrote:

> Can you say more about why you want the tests to run in a particular
> order?


I like to run tests going from common/core modules to more specific ones.
That basically means ordering modules based on its `import`s.

i.e. If bar.py imports foo.py, test_foo.py should be tested before
test_bar.py.

The main advantage is that a change in foo.py might break several tests...
usually the most significant test failure you care is on test_foo.py.
This way you can always look at the first failing test.
It will be faster to see a failure and probably give you the best assertion
error.
Often fixing this first test fixes all, or at least helps you move forward
in the right direction.

I have written a pytest plugin [1] that sort you tests based on imports,
and also skip tests modules that are not affected by changes.
It works well as long as your imports are not messed with circular
imports...


[1] https://github.com/pytest-dev/pytest-incremental

Regards,
  Eduardo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20181010/4e832709/attachment.htm>


More information about the testing-in-python mailing list