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

Win Treese treese at acm.org
Tue Oct 26 10:43:53 PDT 2010


On Oct 26, 2010, at 7:56 AM, Alfredo Deza wrote:

> 
> 
> On Mon, Oct 25, 2010 at 9:43 PM, Win Treese <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.

Thanks for the quick note.

That would make sense, except that the coverage.py documentation at
	http://nedbatchelder.com/code/coverage/source.html
says that
	"When running your code, the coverage run command will by default measure all code, unless it is part of the Python standard library.".
and the json library is part of the Python standard library.

Thanks,

Win

> 
>  
> .
> 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
> 
> 
> 
> 
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
> 




More information about the testing-in-python mailing list