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

Dan Wandschneider daniel.wandschneider at schrodinger.com
Fri May 24 16:05:11 PDT 2013


Try the --source option to coverage run.  If that isn't enough, you may
want the --omit and --include options, available in both run and report.


On Fri, May 24, 2013 at 3:58 PM,
<testing-in-python-request at lists.idyll.org>wrote:

> Send testing-in-python mailing list submissions to
>         testing-in-python at lists.idyll.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://lists.idyll.org/listinfo/testing-in-python
> or, via email, send a message with subject or body 'help' to
>         testing-in-python-request at lists.idyll.org
>
> You can reach the person managing the list at
>         testing-in-python-owner at lists.idyll.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of testing-in-python digest..."
>
> Today's Topics:
>
>    1. How to stop coverage from visiting /usr/local when running
>       pytes? (Steve Wang)
>
>
> ---------- Forwarded message ----------
> From: Steve Wang <fair800 at yahoo.com>
> To: "testing-in-python at lists.idyll.org" <testing-in-python at lists.idyll.org
> >
> Cc:
> Date: Fri, 24 May 2013 15:58:46 -0700 (PDT)
> Subject: [TIP] How to stop coverage from visiting /usr/local when running
> pytes?
> Hi,
>
> I'm trying to introduce pytest and coverage to our project, but I'm
> puzzled by the amount of data collected by coverage that I didn't ask for.
> What can I do to stop coverage from visiting /usr/local? Any
> suggestions/advice? Thanks.
>
> More details:
>
> (1) the simple test script is directly copied out of this page:
> http://pytest.org/latest/getting-started.html#getstarted
>
> ~/lab/proj$ cat test_sample.py
> def func(x):
>     return x + 1
>
> def test_answer():
>     assert func(3) == 5
>
> (2) If I run py.test by hand, the test finished in less than a half a
> second:
>
> ~/lab/proj$ which py.test
> /usr/local/bin/py.test
>
> ~/lab/proj$ 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 0.46 seconds
> ===========================
>
> (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
> ============================= 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20130524/3a1b2f12/attachment-0001.htm>


More information about the testing-in-python mailing list