Pregunta

I am using nose 1.3.0 and coverage 3.7.

Running on a command line

coverage run test_myfile.py
coverage report

produces a report that limits itself to the functions in myfile.py:

Name               Stmts   Miss Branch BrMiss  Cover
----------------------------------------------------
myfile               157     27     38     12    80%
test_myfile           81     16     16     13    70%
----------------------------------------------------
TOTAL                238     43     54     25    77%

If however I try to use the coverage plugin for nose, coverage extends to the installed python libraries with is slow and clutters the results:

nosetests --with-coverage myfile.py

Here coverage extends to all used packages from the installed libraries in all their gory detail (report manually shortened):

Name                                                    Stmts   Miss Branch BrMiss  Cover   Missing
---------------------------------------------------------------------------------------------------
Cookie                                                    201    201     64     64     0%   42-756
_LWPCookieJar                                              93     93     42     42     0%   14-169
_MozillaCookieJar                                          68     68     33     33     0%   3-149
bisect                                                     46     46     32     32     0%   3-92
.
.
.
myfile                                                    157     27     38     12    80%   57-58, 61, 64-67, 83, 114-145
.
.
.
requests.packages.urllib3                                  27     27      0      0     0%   7-58
requests.packages.urllib3._collections                     49     49     10     10     0%   7-94
requests.packages.urllib3.connectionpool                  209    209     50     48     1%   7-597
requests.packages.urllib3.contrib                           0      0      0      0   100%   
requests.packages.urllib3.exceptions                       42     42      2      2     0%   10-95
requests.packages.urllib3.filepost                         40     40     18     18     0%   7-98
requests.packages.urllib3.packages                          2      2      0      0     0%   1-3
.
.
.
sqlalchemy.engine.reflection                              156    156     79     79     0%   7-506
sqlalchemy.engine.result                                  434    434    173    169     1%   7-997
sqlalchemy.engine.strategies                              124    124     40     40     0%   7-260
sqlalchemy.engine.threadlocal                              80     80     28     28     0%   7-134
.
.
.
urllib2                                                   820    820    323    323     0%   92-1470
uuid                                                      293    293    119    119     0%   47-560
---------------------------------------------------------------------------------------------------
TOTAL                                                   35091  34961  14918  14828     1%   
----------------------------------------------------------------------

This seems to be equivalent to specifying on the command line:

coverage run --pylib test_myfile.py

How can I get the nose coverage plugin to not delve into the installed python libraries?

¿Fue útil?

Solución

You should configure it. Here's an example:

# .coveragerc
[report]
include = *.py
omit =
    tests.py
    *_test.py
    *_tests.py
    */site-packages/*
    */migrations/*

Otros consejos

I think you may want to try something like this:

nosetests --with-coverage --cover-package=myfile --cover-tests
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top