<div dir="ltr">It's actually 4 tickets :)<div><br></div><div>Nice, it worked this time, also the html report looks nice.</div><div><br></div><div><div>[root@spahire pyc]# coverage report</div><div>Name Stmts Miss Cover</div>
<div>----------------------------------------------------------------------------</div><div>/root/lucian/coverage/module1/src/main 1 0 100%</div><div>/root/lucian/coverage/module1/src/test_coverage_callee 3 0 100%</div>
<div>/root/lucian/coverage/module1/src/test_coverage_caller 3 0 100%</div><div>----------------------------------------------------------------------------</div><div>TOTAL 7 0 100%</div>
</div><div><br></div><div>What I am after is running coverage against a bigger beast. So can I specify several source directories, corresponding to several components? I don't have the time to test now, so asking first.</div>
<div><br></div><div>Thanks,</div><div>Lucian</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 24, 2013 at 4:12 PM, Ned Batchelder <span dir="ltr"><<a 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/24/13 7:31 AM, Lucian Ciufudean wrote:<br>
<blockquote type="cite">
<div dir="ltr">
<div>Back again, it does not work, neither with a relative or
absolute path in .coveragerc<br>
</div>
<div><br>
</div>
<div>
<div>[root@spahire pyc]# coverage erase</div>
<div>[root@spahire pyc]# ls -la</div>
<div>
total 28</div>
<div>drwxr-xr-x. 2 root root 4096 Sep 24 12:28 .</div>
<div>drwxr-xr-x. 4 root root 4096 Sep 17 15:58 ..</div>
<div>-rw-r--r--. 1 root root 105 Sep 18 14:02 api.py</div>
<div>-rw-r--r--. 1 root root 50 Sep 24 12:24 .coveragerc</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 .coveragerc</div>
<div>[run]</div>
<div>parallel = true</div>
<div><br>
</div>
<div>[paths]</div>
<div>mysources = ../src</div>
</div>
</div>
</blockquote>
<br></div>
Hmm, it looks like there's a little more work for me in
coverage.py. I had meant for your [paths] section to have two lines
in the value: one with "../src", and one with a single dot: "." .
Like this:<div class="im"><br>
<br>
[run]<br>
parallel = true<br>
<br>
[paths]<br>
mysources =<br>
../src<br>
.<br>
<br></div>
This tells "coverage combine" that when it encounters a path to a
file in the current directory, it should remap it to ../src
instead. BUT: relative paths don't work! If you put an absolute
path in for the second entry, it will work:<br>
<br>
[paths]<br>
mysources =<br>
../src<br>
/Users/ned/foo/run<br>
<br>
I've created a ticket to track the fix for relative paths:
<a href="https://bitbucket.org/ned/coveragepy/issue/267/relative-path-aliases-dont-work" target="_blank">https://bitbucket.org/ned/coveragepy/issue/267/relative-path-aliases-dont-work</a><br>
<br>
This has been a very productive exchange! Three tickets! Thanks for
finding these problems, sorry it couldn't have been flawless from
the start..<span class="HOEnZb"><font color="#888888"><br>
<br>
--Ned.</font></span><div><div class="h5"><br>
<blockquote type="cite">
<div dir="ltr">
<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 combine</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><br>
</div>
<div>Lucian</div>
<div><br>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Thu, Sep 19, 2013 at 2:43 AM, Ned
Batchelder <span dir="ltr"><<a 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/18/13 9:10 AM, Lucian Ciufudean
wrote:<br>
<blockquote 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>
</div>
Iterations are fine as long as they bring more detail!
Thanks for putting in all the work.
<div><br>
<br>
<blockquote 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>
</div>
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.
<div><br>
<br>
<blockquote 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>
</div>
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 href="https://bitbucket.org/ned/coveragepy/issue/265/when-using-source-include-is-silently" target="_blank">https://bitbucket.org/ned/coveragepy/issue/265/when-using-source-include-is-silently</a>)
<div><br>
<br>
<blockquote 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>
</div>
Hmm, that seems like an oversight: I should make that
possible (ticket:
<a href="https://bitbucket.org/ned/coveragepy/issue/266/report-command-doesnt-accept-source-option" target="_blank">https://bitbucket.org/ned/coveragepy/issue/266/report-command-doesnt-accept-source-option</a>)
<div>
<br>
<blockquote 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>
</div>
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.
<div><br>
<br>
<blockquote 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>
</div>
Right, same options, specified in a different way.
<div><br>
<blockquote 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>
</div>
Another run with the same (non-)options.
<div><br>
<br>
<blockquote 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>
</div>
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,
<div>
<div><br>
<br>
--Ned.<br>
<br>
<blockquote 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 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/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><font color="#888888"><br>
<br>
--Ned.</font></span>
<div><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 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 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 href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a>
<a 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>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
<br>
</div></div></div>
</blockquote></div><br></div>