[TIP] coverage.py: Unexpected coverage report for library modules

Ned Batchelder ned at nedbatchelder.com
Tue Oct 26 11:10:49 PDT 2010


If Alfredo's advice doesn't fix it, you can also run nose inside 
coverage instead of the usual way:

     $ coverage run nosetests.py

Also, you can specify options to coverage using a .coveragerc file, so 
you could for example set the "source=" option to limit coverage's 
attention to a particular tree of files.

--Ned.

On 10/26/2010 7:56 AM, Alfredo Deza wrote:
>
>
> On Mon, Oct 25, 2010 at 9:43 PM, Win Treese <treese at acm.org 
> <mailto:treese at acm.org>> wrote:
>
>
>     I can't figure out why I'm getting coverage reports for standard
>     library modules with the (most excellent) coverage.py and (also
>     most excellent) nose:
>
>     Python source:
>
>     % cat test.py
>     """Demonstrate coverage of library module."""
>
>     import json
>
>     def test_json():
>       print json.dumps({'a':3})
>
>
>     Run nose with coverage:
>
>     % nosetests --with-cover
>
> You are missing the "--cover-package" flag that specifies what package 
> to track.
>
> This is very useful because sometimes you need a report on a sub-package:
>
> nosetests --with-cover --cover-package=foo.sub_foo
>
> If you do not provide that flag, you are telling the tool to track 
> coverage in everything that is touched by your
> execution.
>
>     .
>     Name                  Stmts   Miss  Cover   Missing
>     ---------------------------------------------------
>     encodings.hex_codec      28     28     0%   9-71
>     json                     39     39     0%   100-323
>     json.decoder            216    216     0%   3-365
>     json.encoder            241    241     0%   3-442
>     json.scanner             52     52     0%   3-67
>     ---------------------------------------------------
>     TOTAL                   576    576     0%
>     ----------------------------------------------------------------------
>     Ran 1 test in 0.012s
>
>     This is on Mac OS X 10.6.4 with:
>
>     $ python --version
>     Python 2.7
>     $ nosetests --version
>     nosetests version 0.11.4
>     $ coverage --version
>     Coverage.py, version 3.4. http://nedbatchelder.com/code/coverage
>
>     >From the documentation, I would expect those modules to be
>     omitted. The coverage information is also incorrect, as if they
>     are being reported, but not actually processed. I tried to trace
>     it down through the code, but couldn't find the problem quickly.
>
>     Thanks for any help,
>
>     Win Treese
>     treese at acm.org <mailto:treese at acm.org>
>
>
>
>
>     _______________________________________________
>     testing-in-python mailing list
>     testing-in-python at lists.idyll.org
>     <mailto:testing-in-python at lists.idyll.org>
>     http://lists.idyll.org/listinfo/testing-in-python
>
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20101026/4cb729bd/attachment.htm>


More information about the testing-in-python mailing list