<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">Hi, <br><br>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. <br>What can I do to stop coverage from visiting /usr/local? Any suggestions/advice? Thanks.<br><br>More details:<br><br>(1) the simple test script is directly copied out of this page: <a target="_blank" href="http://pytest.org/latest/getting-started.html#getstarted">http://pytest.org/latest/getting-started.html#getstarted</a><br><br>~/lab/proj$ cat test_sample.py<br>def func(x):<br> return x + 1<br><br>def test_answer():<br> assert func(3) == 5<br><br>(2) If I run py.test by hand, the test finished in less than a half a
second:<br><br>~/lab/proj$ which py.test<br>/usr/local/bin/py.test<br><br>~/lab/proj$ py.test test_sample.py<br>============================= test session starts ==============================<br>platform linux2 -- Python 2.7.3 -- pytest-2.3.5<br>plugins: cov<br>collected 1 items<br><br>test_sample.py F<br><br>=================================== FAILURES ===================================<br>_________________________________ test_answer __________________________________<br><br> def test_answer():<br>> assert func(3) == 5<br>E assert 4 == 5<br>E + where 4 = func(3)<br><br>test_sample.py:5: AssertionError<br>=========================== 1 failed in 0.46 seconds ===========================<br><br>(3) However, if i run the same test under the control of 'coverage', then it takes a lot more time than I expect<br><br>~/lab/proj$ which
coverage<br>/usr/local/bin/coverage<br><br>~/lab/proj$ coverage erase<br><br>~/lab/proj$ coverage run /usr/local/bin/py.test test_sample.py<br>============================= test session starts ==============================<br>platform linux2 -- Python 2.7.3 -- pytest-2.3.5<br>plugins: cov<br>collected 1 items<br><br>test_sample.py F<br><br>=================================== FAILURES ===================================<br>_________________________________ test_answer __________________________________<br><br> def test_answer():<br>> assert func(3) == 5<br>E assert 4 == 5<br>E + where 4 = func(3)<br><br>test_sample.py:5: AssertionError<br>=========================== 1 failed in 2.96 seconds ===========================<br><br><br>(4) And I noticed that a huge .coverage file was created<br><br>~/lab/proj$ la -l .coverage<br>-rw-r--r-- 1 pi pi 16083 May 24 18:29
.coverage<br><br>(5) And indeed, there's all sorts of data collecte from /usr/local. How can I stop coverage from going there?<br><br>~/lab/proj$ coverage report<br>Name Stmts Miss Cover<br>------------------------------------------------------------------------------------------------------------------<br>/usr/local/bin/py 4 0
100%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/__init__ 5 0 100%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_apipkg 131 34 74%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_builtin 188 140 26%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_code/__init__ 0 0 100%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_code/code
518 172 67%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_code/source 294 155 47%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_error 50 11 78%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_io/__init__ 0 0 100%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_io/capture 264 114 57%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_io/saferepr
35 16 54%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_io/terminalwriter 215 149 31%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_path/__init__ 0 0 100%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_path/common 232 113 51%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_path/local 558 356 36%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_std
11 5 55%<br>/usr/local/lib/python2.7/dist-packages/py-1.4.14-py2.7.egg/py/_xmlgen 168 114 32%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/__init__ 1 0 100%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/__init__ 78 15 81%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/newinterpret 244 171 30%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/oldinterpret 402 327
19%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/reinterpret 36 12 67%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/rewrite 436 302 31%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/assertion/util 172 114 34%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/capture 163 52 68%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/config 355 120 66%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/core
387 106 73%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/doctest 75 54 28%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/genscript 51 38 25%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/helpconfig 138 79 43%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/hookspec 57 0 100%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/junitxml
142 92 35%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/main 463 131 72%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/mark 131 72 45%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/monkeypatch 71 40 44%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/nose 37 12 68%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/pastebin
56 38 32%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/pdb 73 44 40%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/python 1163 631 46%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/recwarn 65 52 20%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/resultlog 80 62 23%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/runner 289
101 65%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/skipping 197 134 32%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/terminal 382 171 55%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/tmpdir 42 24 43%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/_pytest/unittest 147 115 22%<br>/usr/local/lib/python2.7/dist-packages/pytest-2.3.5-py2.7.egg/pytest 8
2 75%<br>/usr/local/lib/python2.7/dist-packages/pytest_cov-1.6-py2.7.egg/pytest_cov 44 27 39%<br>/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg/pkg_resources 1247 996 20%<br>test_sample 4 0 100%<br>------------------------------------------------------------------------------------------------------------------<br>TOTAL
9909 5513 44%<br></span><br></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">(5) Finally, I did try the -omit switch, however, it still took a long time. </span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">It feels like that coverage went to /usr/local anyway, collected the data and then threw it away.</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">I don't have hard evidence that it did
that. I tried to use pdb to step into coverage</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">but failed to see exactly what it was doing.</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;"><br></span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">~/lab/proj$ coverage run --omit=/usr/local/* /usr/local/bin/py.test test_sample.py</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">============================= test session starts ==============================</span></div><div style="background-color: transparent;"><span style="font-family:
'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">platform linux2 -- Python 2.7.3 -- pytest-2.3.5</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">plugins: cov</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">collected 1 items</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;"><br></span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">test_sample.py F</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size:
10px;"><br></span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">=================================== FAILURES ===================================</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">_________________________________ test_answer __________________________________</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;"><br></span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;"> def test_answer():</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace,
sans-serif; font-size: 10px;">> assert func(3) == 5</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">E assert 4 == 5</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">E + where 4 = func(3)</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;"><br></span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">test_sample.py:5: AssertionError</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;
font-size: 10px;">=========================== 1 failed in 2.91 seconds ===========================</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;"></span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10px;">~/lab/proj$ </span></div></div></body></html>