<div dir="ltr">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.<br><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, May 24, 2013 at 3:58 PM, <span dir="ltr"><<a href="mailto:testing-in-python-request@lists.idyll.org" target="_blank">testing-in-python-request@lists.idyll.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Send testing-in-python mailing list submissions to<br>
<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:testing-in-python-request@lists.idyll.org">testing-in-python-request@lists.idyll.org</a><br>
<br>
You can reach the person managing the list at<br>
<a href="mailto:testing-in-python-owner@lists.idyll.org">testing-in-python-owner@lists.idyll.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of testing-in-python digest..."<br>
<br>Today's Topics:<br>
<br>
1. How to stop coverage from visiting /usr/local when running<br>
pytes? (Steve Wang)<br>
<br><br>---------- Forwarded message ----------<br>From: Steve Wang <<a href="mailto:fair800@yahoo.com">fair800@yahoo.com</a>><br>To: "<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>" <<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>><br>
Cc: <br>Date: Fri, 24 May 2013 15:58:46 -0700 (PDT)<br>Subject: [TIP] How to stop coverage from visiting /usr/local when running pytes?<br><div><div style="font-size:12pt;font-family:'times new roman','new york',times,serif">
<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 href="http://pytest.org/latest/getting-started.html#getstarted" target="_blank">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></div><br>_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br></blockquote></div><br></div></div>