<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    On 8/5/14 2:47 PM, Barry Warsaw wrote:<br>
    <blockquote cite="mid:20140805144747.6a2951a0@anarchist.wooz.org"
      type="cite">
      <pre wrap="">I have a Python 3 project with an extensive test suite for which I want to
gather coverage data.  I use nose2 as the test runner.  While I get accurate
coverage for the parent process tests, covering subprocesses just isn't
working afaict.

I suspect the tricky part here is that the subprocesses are D-Bus services
which get activated via a custom system bus run with dbus-daemon.  However,
I've verified that environment variables are being seen by these subprocs,
including COVERAGE_PROCESS_START which points to the correct coverage.ini
file.

That .ini file contains roughly:

-----snip snip-----
[run]
branch = true
parallel = true
omit =
     setup*
     ...
-----snip snip-----

but after the full test suite runs I see only one .coverage file such as:

.coverage.&lt;hostname&gt;.&lt;parent-pid&gt;.&lt;random&gt;

meaning, that only the parent process is getting covered.  I'd expect to see
about a dozen subproc .coverage files.

When I debug-print the D-Bus activated subprocs, I can see the environment
variable, and its pid, along with its cwd, which is /.  Thinking that maybe
coverage is trying to write the default .coverage.* files in cwd, I've tried
both setting COVERAGE_FILE and chdir'ing to the proper directory.  Neither has
worked.

My subprocs start coverage like so, early on in their main().

    ini_file = os.environ.get('COVERAGE_PROCESS_START')
    if ini_file is not None:
        try:
            import coverage
        except ImportError:
            pass
        else:
            coverage.process_startup()

With some debug-printing in the else: clause, I can see that we get through
coverage.process_startup().

Still, I get no data from the subprocs.  My tests that activate the service
all pass, so I know the subprocs are running.

My only guess at the moment is that setting [run]parallel=true in the .ini
file isn't enough to turn on parallel mode.  I can't really pass
-p/--parallel-mode to the subprocesses so I'm relying on .process_startup() to
get coverage going.
</pre>
    </blockquote>
    <br>
    Your data file has the machine name, pid, and random number, which
    is an artifact of parallel mode, so that seems fine.<br>
    <br>
    Could it be due to an os._exit() after forking?&nbsp;
<a class="moz-txt-link-freetext" href="https://bitbucket.org/ned/coveragepy/issue/310/coverage-fails-with-osfork-and-os_exit">https://bitbucket.org/ned/coveragepy/issue/310/coverage-fails-with-osfork-and-os_exit</a><br>
    <br>
    If you have ideas about how to support that, I'm open to them.<br>
    <br>
    --Ned.<br>
    <blockquote cite="mid:20140805144747.6a2951a0@anarchist.wooz.org"
      type="cite">
      <pre wrap="">
I'm stuck at the moment, so would appreciate in advance any thoughts on what
to try next or what I might be doing wrong.

Cheers,
-Barry
</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
testing-in-python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
<a class="moz-txt-link-freetext" href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>