简体   繁体   中英

How can you get unittest2 and coverage.py working together?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM