<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>[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: &#39;/root/lucian/coverage/module1/pyc/test_coverage_callee.py&#39;</div><div>test_coverage_caller   NoSource: No source for code: &#39;/root/lucian/coverage/module1/pyc/test_coverage_caller.py&#39;</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">&lt;<a href="mailto:ned@nedbatchelder.com" target="_blank">ned@nedbatchelder.com</a>&gt;</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 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 class="im"><br>
    <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div>
          <div>After not being able to run &#39;coverage run pyc_file.pyc&#39;,
            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&#39;t collected any data.<div class="im"><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=&#39;*&#39; 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&#39;ve already told coverage that
    the only interesting files are in ../src, so there&#39;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 class="im"><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=&#39;*test*&#39;</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 class="im">

<br>
    <blockquote type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>[root@spahire pyc]# coverage report --include=&#39;*test*&#39;
              --source=../src</div>
            <div>no such option: --source</div>
            <div>Use &#39;coverage help&#39; 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:
&#39;/root/lucian/coverage/module1/pyc/test_coverage_callee.py&#39;</div>
              <div>test_coverage_caller   NoSource: No source for code:
&#39;/root/lucian/coverage/module1/pyc/test_coverage_caller.py&#39;</div>
            </div>
          </div>
          <div><br>
          </div>
        </div>
      </div>
    </blockquote></div>
    The problem is that you haven&#39;t told coverage how to find the source
    files that correspond to your .pyc files.  The --source option
    doesn&#39;t do that.<div class="im"><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 class="im"><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 class="im"><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 &quot;coverage run main.py&quot;, then &quot;coverage combine&quot;, then
    &quot;coverage report&quot;.  If that works, we can talk about how to make it
    a bit easier.<br>
    <br>
    Hope that helps,<div><div class="h5"><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">&lt;<a href="mailto:ned@nedbatchelder.com" target="_blank">ned@nedbatchelder.com</a>&gt;</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&#39;t mention the exact errors you saw (details
                matter), but in your previous message you mentioned the
                problem being while reporting.  You&#39;ll also have to
                specify the source directory during the &quot;coverage html&quot;
                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">&lt;<a href="mailto:ned@nedbatchelder.com" target="_blank">ned@nedbatchelder.com</a>&gt;</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&#39;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&#39;re right: &quot;coverage run foo.pyc&quot;
                            does not work. I&#39;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&#39;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>