Reputation: 10409
I'm trying to wrangle nose + coverage. If I have this code:
class Foobar(object):
def add(self, a, b):
return a + b
And this test:
from unittest import TestCase
from foobar import Foobar
class FoobarTest(TestCase):
def test_good(self):
f = Foobar()
self.assertEquals(f.add(1,2), 3)
Then everything looks good!
$ nosetests
.
Name Stmts Miss Cover Missing
-----------------------------------------
foobar.py 3 0 100%
----------------------------------------------------------------------
Ran 1 test in 0.018s
OK
But if I add one line to my source code
import requests
class Foobar(object):
def add(self, a, b):
return a + b
then I get lots of extra stuff in my report
$ nosetests
.
Name Stmts Miss Cover Missing
--------------------------------------------------------------------------------------------------------
foobar.py 4 0 100%
requests.py 26 5 81% 54, 72-75
requests/adapters.py 180 134 26% 48, 51, 54, 89-102, 105, 111-117, 1
[snip]
So how do I configure coverage to say "don't bother measuring or reporting anything that is part of my virtualenv -- just do the stuff under my working directory." I'm sure it has something to do with .coveragerc, but I'm having some trouble getting the invocation correct.
Upvotes: 2
Views: 963
Reputation: 10409
Figured it out.
1) Get rid of any coverage-related ini files
2) add this in "nose.cfg" in your home directory for the nose stuff
[nosetests]
with-coverage=1 ; generate a coverage report (in the "cover" directory)
cover-package=. ; only report on coverage files in the current directory
cover-html=1 ; generate a pretty html report
cover-erase=1 ; re-generate coverage statistics on each run
and of course, you have to be sure that your test files match the testMatch pattern that Nose is looking for.
Upvotes: 3