Skip to content

Commit fb100db

Browse files
committed
Patch py.process.ForkedFunc to clean up coverage.
1 parent 1fe3c48 commit fb100db

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pytest_cov.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@
44
import pytest
55

66
import cov_core
7+
import cov_core_init
8+
9+
from py._process import forkedfunc
10+
11+
12+
class PatchedForkedFunc(forkedfunc.ForkedFunc):
13+
14+
def _child(self, nice_level):
15+
import os
16+
_exit = os._exit
17+
exit_args = list()
18+
19+
def _capture_args(*args):
20+
exit_args.extend(list(args))
21+
22+
os._exit = _capture_args
23+
24+
cov = cov_core_init.init()
25+
try:
26+
super(PatchedForkedFunc, self)._child(nice_level)
27+
finally:
28+
cov_core.multiprocessing_finish(cov)
29+
_exit(*exit_args)
30+
31+
forkedfunc.ForkedFunc = PatchedForkedFunc
32+
33+
from py import process
34+
process.ForkedFunc = PatchedForkedFunc
735

836

937
def pytest_addoption(parser):

0 commit comments

Comments
 (0)