<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 9/18/13 9:10 AM, Lucian Ciufudean wrote:<br>
<blockquote
cite="mid:CANn=0kztNT1e=MrM0_wxMFCqLNbz=s5u+iUMdPPQ-Pu6BHD3Dg@mail.gmail.com"
type="cite">
<div dir="ltr">Sorry for all these iterations, here is a more
consistent (but long) email.
<div>
<div><br>
</div>
</div>
</div>
</blockquote>
Iterations are fine as long as they bring more detail! Thanks for
putting in all the work.<br>
<br>
<blockquote
cite="mid:CANn=0kztNT1e=MrM0_wxMFCqLNbz=s5u+iUMdPPQ-Pu6BHD3Dg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>After not being able to run 'coverage run pyc_file.pyc',
I created a dummy driver main.py file that uses the compiled
modules.</div>
<div><br>
</div>
<div>
<div>root@spahire pyc]# ls -la</div>
<div>total 20</div>
<div>drwxr-xr-x. 2 root root 4096 Sep 18 13:20 .</div>
<div>drwxr-xr-x. 4 root root 4096 Sep 17 15:58 ..</div>
<div>-rw-r--r--. 1 root root 28 Sep 18 13:01 main.py</div>
<div>-rw-------. 1 root root 187 Sep 17 15:59
test_coverage_callee.pyc</div>
<div>-rw-------. 1 root root 212 Sep 17 15:59
test_coverage_caller.pyc</div>
<div>[root@spahire pyc]# cat main.py</div>
<div>import test_coverage_caller</div>
</div>
<div><br>
</div>
<div>The source files for the 2 pyc files are here:</div>
<div><br>
</div>
<div>
<div>[root@spahire pyc]# ls ../src</div>
<div>test_coverage_callee.py test_coverage_caller.py</div>
</div>
<div><br>
</div>
<div>
Further, I run coverage, I get a warning but a data file
.coverage is created:</div>
<div><br>
</div>
<div>
<div>[root@spahire pyc]# coverage run --source=../src
main.py</div>
<div>1</div>
<div>2</div>
<div>2.1</div>
<div>2.2</div>
<div>2.3</div>
<div>Coverage.py warning: No data was collected.</div>
<div>[root@spahire pyc]# ls -l .coverage</div>
<div>-rw-r--r--. 1 root root 180 Sep 18 13:23 .coverage</div>
<div><br>
</div>
</div>
</div>
</div>
</blockquote>
The --source option tells coverage that the only files of interest
are the ones in ../src. You never execute any files in ../src, so
coverage hasn't collected any data.<br>
<br>
<blockquote
cite="mid:CANn=0kztNT1e=MrM0_wxMFCqLNbz=s5u+iUMdPPQ-Pu6BHD3Dg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>--include does not make a difference:</div>
<div><br>
</div>
<div>
<div>[root@spahire pyc]# coverage run --source=../src
--include='*' main.py</div>
<div>1</div>
<div>2</div>
<div>2.1</div>
<div>2.2</div>
<div>2.3</div>
<div>Coverage.py warning: No data was collected.</div>
<div>[root@spahire pyc]# ls -l .coverage</div>
<div>-rw-r--r--. 1 root root 180 Sep 18 13:38 .coverage</div>
</div>
<div><br>
</div>
</div>
</div>
</blockquote>
Right, --source trumps --include. You've already told coverage that
the only interesting files are in ../src, so there's nothing else to
include. I should make a warning for inconsistent options like this
(ticket:
<a class="moz-txt-link-freetext" href="https://bitbucket.org/ned/coveragepy/issue/265/when-using-source-include-is-silently">https://bitbucket.org/ned/coveragepy/issue/265/when-using-source-include-is-silently</a>)<br>
<br>
<blockquote
cite="mid:CANn=0kztNT1e=MrM0_wxMFCqLNbz=s5u+iUMdPPQ-Pu6BHD3Dg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>As expected, report shows nothing is covered:</div>
<div><br>
</div>
<div>
<div>[root@spahire pyc]# coverage report --include='*test*'</div>
<div>Name
Stmts Miss Cover</div>
<div>----------------------------------------------------------------------------</div>
<div>/root/lucian/coverage/module1/src/test_coverage_callee
3 3 0%</div>
<div>/root/lucian/coverage/module1/src/test_coverage_caller
3 3 0%</div>
<div>----------------------------------------------------------------------------</div>
<div>TOTAL
6 6 0%</div>
<div><br>
</div>
<div>report does not accept --source, might this be the root
to all evil?</div>
<div><br>
</div>
</div>
</div>
</div>
</blockquote>
Hmm, that seems like an oversight: I should make that possible
(ticket:
<a class="moz-txt-link-freetext" href="https://bitbucket.org/ned/coveragepy/issue/266/report-command-doesnt-accept-source-option">https://bitbucket.org/ned/coveragepy/issue/266/report-command-doesnt-accept-source-option</a>)<br>
<blockquote
cite="mid:CANn=0kztNT1e=MrM0_wxMFCqLNbz=s5u+iUMdPPQ-Pu6BHD3Dg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>[root@spahire pyc]# coverage report --include='*test*'
--source=../src</div>
<div>no such option: --source</div>
<div>Use 'coverage help' for help.</div>
</div>
<div><br>
</div>
<div>No warning when using run without options, but the report
is again wrong:</div>
<div><br>
</div>
<div>
<div>
<div>[root@spahire pyc]# coverage run main.py</div>
<div>1</div>
<div>2</div>
<div>2.1</div>
<div>2.2</div>
<div>2.3</div>
<div>[root@spahire pyc]# coverage report</div>
<div>Name Stmts Miss Cover</div>
<div>------------------------------------------</div>
<div>
main 1 0 100%</div>
<div>test_coverage_callee NoSource: No source for code:
'/root/lucian/coverage/module1/pyc/test_coverage_callee.py'</div>
<div>test_coverage_caller NoSource: No source for code:
'/root/lucian/coverage/module1/pyc/test_coverage_caller.py'</div>
</div>
</div>
<div><br>
</div>
</div>
</div>
</blockquote>
The problem is that you haven't told coverage how to find the source
files that correspond to your .pyc files. The --source option
doesn't do that.<br>
<br>
<blockquote
cite="mid:CANn=0kztNT1e=MrM0_wxMFCqLNbz=s5u+iUMdPPQ-Pu6BHD3Dg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>Same thing with a configuration file:</div>
<div>
<div>[root@spahire pyc]# cat .coveragerc</div>
<div>[run]</div>
<div>source=../src/</div>
<div>include=*</div>
</div>
<div><br>
</div>
</div>
</div>
</blockquote>
Right, same options, specified in a different way.<br>
<blockquote
cite="mid:CANn=0kztNT1e=MrM0_wxMFCqLNbz=s5u+iUMdPPQ-Pu6BHD3Dg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>So now I turn to the api + the same .coveragerc, the same
thing:</div>
<div><br>
</div>
<div>
<div>[root@spahire pyc]# cat api.py</div>
<div>import coverage</div>
<div>cov = coverage.coverage()</div>
<div>cov.start()</div>
<div>import test_coverage_caller</div>
<div>cov.stop()</div>
<div>cov.save()</div>
<div><br>
</div>
<div>[root@spahire pyc]# python api.py</div>
<div>1</div>
<div>2</div>
<div>2.1</div>
<div>2.2</div>
<div>2.3</div>
<div>Coverage.py warning: No data was collected.</div>
</div>
</div>
<div><br>
</div>
</div>
</blockquote>
Another run with the same (non-)options.<br>
<br>
<blockquote
cite="mid:CANn=0kztNT1e=MrM0_wxMFCqLNbz=s5u+iUMdPPQ-Pu6BHD3Dg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>As for your suggestion with [paths], the docs suggest to me
that this is for combining data.</div>
</div>
</blockquote>
Yes, it is used when combining data, I should have fleshed out my
idea more fully. Try creating a .coveragerc file like this:<br>
<br>
[run]<br>
parallel = true<br>
<br>
[paths]<br>
mysources =<br>
../src<br>
.<br>
<br>
Then use "coverage run main.py", then "coverage combine", then
"coverage report". If that works, we can talk about how to make it
a bit easier.<br>
<br>
Hope that helps,<br>
<br>
--Ned.<br>
<br>
<blockquote
cite="mid:CANn=0kztNT1e=MrM0_wxMFCqLNbz=s5u+iUMdPPQ-Pu6BHD3Dg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
<div>Lucian</div>
<div><br>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Wed, Sep 18, 2013 at 1:20 PM, Ned
Batchelder <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:ned@nedbatchelder.com" target="_blank">ned@nedbatchelder.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div class="im"> On 9/18/13 3:42 AM, Lucian Ciufudean
wrote:<br>
<blockquote type="cite">
<div dir="ltr">Here is how I ran coverage:
<div><br>
</div>
<div> coverage run --source=../src main.py<br>
</div>
<div><br>
</div>
<div>main.py imports a pyc file that resides in
the same folder. The source of this pyc file is
available in ../src.</div>
<div>(I created main.py just to go around the bug
that you submitted above)</div>
<div><br>
</div>
</div>
</blockquote>
</div>
You don't mention the exact errors you saw (details
matter), but in your previous message you mentioned the
problem being while reporting. You'll also have to
specify the source directory during the "coverage html"
command (or coverage.html() call). A good way to do
this is with a .coveragerc file.<span class="HOEnZb"><font
color="#888888"><br>
<br>
--Ned.</font></span>
<div class="im"><br>
<br>
<blockquote type="cite">
<div dir="ltr">
<div>Lucian</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Wed, Sep 18, 2013 at
5:05 AM, Ned Batchelder <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:ned@nedbatchelder.com"
target="_blank">ned@nedbatchelder.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0
0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div> On 9/17/13 7:42 AM, Lucian Ciufudean
wrote:<br>
<blockquote type="cite">
<div dir="ltr">Hi guys,
<div><br>
</div>
<div>I embarked on the road of
obtaining a coverage report for
functional tests against a server
process. The server is deployed as
.pyc files, and the source files can
be made available in a separate
subversion working folder. I
wouldn't want to edit any existing
.py files.</div>
<div><br>
</div>
<div>Can coverage work with .pyc files
- I am getting errors when using
coverage run main.pyc from the
command line, so maybe with the API?
<br>
</div>
</div>
</blockquote>
<br>
</div>
Hmm, you're right: "coverage run foo.pyc"
does not work. I've created a ticket for
this: <a moz-do-not-send="true"
href="https://bitbucket.org/ned/coveragepy/issue/264/coverage-wont-run-pyc-files"
target="_blank">https://bitbucket.org/ned/coveragepy/issue/264/coverage-wont-run-pyc-files</a>
<div><br>
<br>
<blockquote type="cite">
<div dir="ltr">
<div>I tired this also, my custom code
is run but it can not find the
source files at the time of
coverage.html_report() although I
passed the directory of source files
to coverage.coverage.</div>
</div>
</blockquote>
<br>
</div>
You'll have to show details of how you tried
to run coverage. If the .py files are in
the places reported by your program, then it
should work. You can also use the [paths]
section of a .coveragerc to instruct
coverage where the files are.<br>
<br>
--Ned.<br>
<br>
<blockquote type="cite">
<div dir="ltr">
<div><br>
</div>
<div>Thanks a lot,</div>
<div>Lucian</div>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
testing-in-python mailing list
<a moz-do-not-send="true" href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a>
<a moz-do-not-send="true" href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a>
</pre>
</blockquote>
<br>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
<br>
</body>
</html>