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

4

21

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.

Lowenstern answered 22/7, 2010 at 19:8 Comment(1)
I get $ coverage run unit2 discover Coverage.py warning: No data was collected. No file to run: 'unit2' I'm running Python 2.7 on OS X 10.6.8.Messiaen
W
47

Try:

coverage run -m unittest discover

works for me.

Waldon answered 2/7, 2012 at 21:25 Comment(0)
E
5

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.)

Earhart answered 6/2, 2011 at 21:54 Comment(0)
O
3

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
Omnivorous answered 5/12, 2011 at 15:47 Comment(0)
G
1

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.

Grammer answered 24/1, 2015 at 3:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.