[TIP] How to stop coverage from visiting /usr/local when running pytes?

holger krekel holger at merlinux.eu
Sun May 26 04:28:04 PDT 2013


On Fri, May 24, 2013 at 15:58 -0700, Steve Wang wrote:
> (3) However, if i run the same test under the control of 'coverage', then it takes a lot more time than I expect
> 
> ~/lab/proj$ which coverage
> /usr/local/bin/coverage
> 
> ~/lab/proj$ coverage erase
> 
> ~/lab/proj$ coverage run /usr/local/bin/py.test test_sample.py

you could also do "pip install pytest-cov" and then:

    $ py.test --cov=test_sample.py

See also other pytest-cov options with "py.test --help"

cheers,
holger


    

> ============================= test session starts ==============================
> platform linux2 -- Python 2.7.3 -- pytest-2.3.5
> plugins: cov
> collected 1 items
> 
> test_sample.py F
> 
> =================================== FAILURES ===================================
> _________________________________ test_answer __________________________________
> 
>     def test_answer():
> >       assert func(3) == 5
> E       assert 4 == 5
> E        +  where 4 = func(3)
> 
> test_sample.py:5: AssertionError
> =========================== 1 failed in 2.96 seconds ===========================
> 
> 
> (4) And I noticed that a huge .coverage file was created
> 
> ~/lab/proj$ la -l .coverage
> -rw-r--r-- 1 pi pi 16083 May 24 18:29 .coverage
> 
> (5) And indeed, there's all sorts of data collecte from /usr/local. How can I stop coverage from going there?
> 
> ~/lab/proj$ coverage report
> Name                                                                                           Stmts   Miss  Cover
> ------------------------------------------------------------------------------------------------------------------
> /usr/local/bin/py                                                                                  4      0   100%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/__init__                             5      0   100%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_apipkg                            131     34    74%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_builtin                           188    140    26%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_code/__init__                       0      0   100%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_code/code                         518    172    67%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_code/source                       294    155    47%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_error                              50     11    78%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_io/__init__                         0      0   100%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_io/capture                        264    114    57%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_io/saferepr                        35     16    54%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_io/terminalwriter                 215    149    31%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_path/__init__                       0      0   100%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_path/common                       232    113    51%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_path/local                        558    356    36%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_std                                11      5    55%
> /usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_xmlgen                            168    114    32%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/__init__                     1      0   100%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/__init__          78     15    81%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/newinterpret     244    171    30%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/oldinterpret     402    327    19%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/reinterpret       36     12    67%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/rewrite          436    302    31%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/util             172    114    34%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/capture                    163     52    68%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/config                     355    120    66%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/core                       387    106    73%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/doctest                     75     54    28%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/genscript                   51     38    25%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/helpconfig                 138     79    43%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/hookspec                    57      0   100%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/junitxml                   142     92    35%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/main                       463    131    72%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/mark                       131     72    45%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/monkeypatch                 71     40    44%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/nose                        37     12    68%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/pastebin                    56     38    32%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/pdb                         73     44    40%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/python                    1163    631    46%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/recwarn                     65     52    20%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/resultlog                   80     62    23%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/runner                     289    101    65%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/skipping                   197    134    32%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/terminal                   382    171    55%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/tmpdir                      42     24    43%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/unittest                   147    115    22%
> /usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/pytest                               8      2    75%
> /usr/local/lib/python2.7/dist-packages/pytest_cov-1.6-py2.7.egg/pytest_cov                        44     27    39%
> /usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources                1247    996    20%
> test_sample                                                                                        4      0   100%
> ------------------------------------------------------------------------------------------------------------------
> TOTAL                                                                                           9909   5513    44%
> 
> 
> (5) Finally, I did try the -omit switch, however, it still took a long time. 
> It feels like that coverage went to /usr/local anyway, collected the data and then threw it away.
> I don't have hard evidence that it did that. I tried to use pdb to step into coverage
> but failed to see exactly what it was doing.
> 
> ~/lab/proj$ coverage run --omit=/usr/local/* /usr/local/bin/py.test test_sample.py
> ============================= test session starts ==============================
> platform linux2 -- Python 2.7.3 -- pytest-2.3.5
> plugins: cov
> collected 1 items
> 
> test_sample.py F
> 
> =================================== FAILURES ===================================
> _________________________________ test_answer __________________________________
> 
>     def test_answer():
> >       assert func(3) == 5
> E       assert 4 == 5
> E        +  where 4 = func(3)
> 
> test_sample.py:5: AssertionError
> =========================== 1 failed in 2.91 seconds ===========================
> ~/lab/proj$ 

> _______________________________________________
> 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