How can you get unittest2
开发者_如何学编程and coverage.py
working together?
In theory something like
coverage run unit2 discover
should work, but it currently just errors out.
If you are a nose
user that will be the equivalent of nosetests --with-coverage
.
Try:
coverage run -m unittest discover
works for me.
This must be specific to your installation since it works fine for me
coverage run unit2 discover
to generate the coverage information then
coverage html
to generate the an HTML report (one of several reporting formats), and
open htmlcov/index.html
to see the results.
(Answering this because this is a top ghit for "unittest2 coverage" and I don't want people put off by the lack of any answer.)
I am running Windows and encountered the same problem.
$ coverage run unit2 discover
No file to run: 'unit2'
I suspect this is related to differences in how the system path and python path are handled on various operating systems (I'm guessing Andrew is running linux?). Regardless, coverage run
takes a -m
option which allows you to run a module rather than a script. This is what I use:
coverage run -m unittest2 discover
In case you have multiple versions of coverage
installed, use
coverage2 run -m unittest discover
or
coverage3 run -m unittest discover
to specify which one you're going to run.
精彩评论