Skip to content

Commit

Permalink
Fix coverage reporting of subprocess in coverage 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalresistor committed Dec 19, 2019
1 parent dfb9501 commit 1809765
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

testing_extras = [
"nose",
"coverage",
"coverage>=5.0",
]

setup(
Expand Down
15 changes: 7 additions & 8 deletions waitress/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,10 @@ def start_server(app, svr, queue, **kwargs): # pragma: no cover

def try_register_coverage(): # pragma: no cover
# Hack around multiprocessing exiting early and not triggering coverage's
# atexit handler by trapping the SIGTERM and saving coverage explicitly.
if "_COVERAGE_RCFILE" in os.environ:
import coverage

cov = coverage.Coverage(config_file=os.getenv("_COVERAGE_RCFILE"))
cov.start()
# atexit handler by always registering a signal handler

if "COVERAGE_PROCESS_START" in os.environ:
def sigterm(*args):
cov.stop()
cov.save()
sys.exit(0)

signal.signal(signal.SIGTERM, sigterm)
Expand Down Expand Up @@ -78,10 +72,15 @@ class SubprocessTests(object):
def start_subprocess(self, target, **kw):
# Spawn a server process.
self.queue = multiprocessing.Queue()

if "COVERAGE_RCFILE" in os.environ:
os.environ["COVERAGE_PROCESS_START"] = os.environ["COVERAGE_RCFILE"]

self.proc = multiprocessing.Process(
target=start_server, args=(target, self.server, self.queue), kwargs=kw,
)
self.proc.start()

if self.proc.exitcode is not None: # pragma: no cover
raise RuntimeError("%s didn't start" % str(target))
# Get the socket the server is listening on.
Expand Down

0 comments on commit 1809765

Please sign in to comment.