... and a pony! No, seriously. I am looking for a way to organize tests that "just works". Most things do work, but not all pieces fit together. So here is what I want:
- Having tests automatically discovered. This includes doctests. Note that the sum of doctests must not appear as a single test. (i.e. not what py.test --doctest-modules does)
- Being able to run tests in parallel. (Something like py.test -n from xdist)
- Generating a coverage report.
- Make
python setup.py test
just work.
My current approach involves a tests
directory and the load_tests protocol. All files contained are named like test_*.py
. This makes python -m unittest discover
just work, if I create a file test_doctests.py
with the following content.
import doctest
import mymodule1, mymodule2
def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite(mymodule1))
tests.addTests(doctest.DocTestSuite(mymodule2))
return tests
This approach also has the upside that one can use setuptools and supply setup(test_suite="unittest2.collector")
.
However this approach has a few problems.
- coverage.py expects to run a script. So I cannot use unittest2 discovery here.
- py.test does not run load_tests functions, so it does not find the doctests and the
--doctest-modules
option is crap. - nosetests runs the
load_tests
functions, but does not supply any parameters. This appears totally broken on the side of nose.
How can I make things work better than this or fix some of the issues above?
coverage -m unittest2 discover
should work (at least it does forunittest
in Py2.7). – Margarito