[TIP] coverage.py and os.fork()?

Joe Malicki jmalicki at gmail.com
Mon Mar 15 02:10:27 PDT 2010


I dug in enough to realize it seemed to be a fairly fatal flaw of how
parallel=True was implemented.

Issue and provisional patch that seem to work for me here:

http://bitbucket.org/ned/coveragepy/issue/56/

Thanks!
Joe

On Sun, Mar 14, 2010 at 7:38 PM, Joe Malicki <jmalicki at gmail.com> wrote:
> Does anyone have a recipe of getting coverage.py to work across a fork()?
>
> I was trying to use coverage 3.3.1 with python 2.6 and
> multiprocessing, and couldn't figure out how to get it to trace the
> child.
> Attached is a simple test program to illustrate behavior and show
> things I tried.
>
> Is there another way of doing this I didn't come across, or is this
> something that needs to be hacked into coverage?
>
> Thanks!
> Joe
>
> with coverage run -p testcover.py, i see:
>
> jmalicki at boott-spur:~$ coverage combine
> jmalicki at boott-spur:~$ coverage report -m
> Name        Stmts   Exec  Cover   Missing
> -----------------------------------------
> testcover      19     10    52%   10-20, 27
>
> When I explicitly call stop: coverage run -p testcover.py -t
> Child!
> Traceback (most recent call last):
>  File "testcover.py", line 32, in <module>
>    main(sys.argv)
>  File "testcover.py", line 27, in main
>    child(args)
>  File "testcover.py", line 18, in child
>    coverage.stop()
>  File "/usr/local/lib/python2.6/dist-packages/coverage-3.3.1-py2.6-linux-x86_64.egg/coverage/__init__.py",
> line 39, in wrapper
>    return getattr(_the_coverage, name)(*args, **kwargs)
>  File "/usr/local/lib/python2.6/dist-packages/coverage-3.3.1-py2.6-linux-x86_64.egg/coverage/control.py",
> line 212, in stop
>    self.collector.stop()
>  File "/usr/local/lib/python2.6/dist-packages/coverage-3.3.1-py2.6-linux-x86_64.egg/coverage/collector.py",
> line 214, in stop
>    assert self._collectors[-1] is self
> AssertionError
>
> coverage run -p testcover.py -s
> Child!
> jmalicki at boott-spur:~$ coverage combine
> coverage report -m:
> Name        Stmts   Exec  Cover   Missing
> -----------------------------------------
> testcover      19     10    52%   10-20, 27
>



More information about the testing-in-python mailing list