diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-12-30 12:30:09 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-12-30 12:30:09 -0500 |
commit | 09646ef678a07f24c438269c691bd0077924e43d (patch) | |
tree | a55e403da784837a8cc08fe1f3d3e52dc2fa14bf | |
parent | 88d50e9207e01c0e7561d272e52844bbe81eaea6 (diff) | |
download | python-coveragepy-git-09646ef678a07f24c438269c691bd0077924e43d.tar.gz |
Don't warn about trace=None on PyPy at shutdown
PyPy clears the trace function before calling atexit functions. So when we
check if the trace function is changed, don't warn in that specific case.
--HG--
extra : amend_source : a4e946f94b9b84d351a9e112a7eea6a3337bacf1
-rw-r--r-- | CHANGES.rst | 4 | ||||
-rw-r--r-- | coverage/pytracer.py | 15 |
2 files changed, 16 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index d502612a..e9c32fbc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,10 @@ Unreleased process, you could crash Python with a "Fatal Python error: deallocating None" error. This is now fixed. Thanks to Alex Groce for the bug report. +- On PyPy, measuring coverage in subprocesses could produce a warning: "Trace + function changed, measurement is likely wrong: None". This was spurious, and + has been suppressed. + Version 4.3.1 --- 2016-12-28 ---------------------------- diff --git a/coverage/pytracer.py b/coverage/pytracer.py index 23f4946c..13a3b0c8 100644 --- a/coverage/pytracer.py +++ b/coverage/pytracer.py @@ -3,6 +3,7 @@ """Raw data collector for coverage.py.""" +import atexit import dis import sys @@ -52,6 +53,10 @@ class PyTracer(object): self.thread = None self.stopped = False + self.in_atexit = False + # On exit, self.in_atexit = True + atexit.register(setattr, self, 'in_atexit', True) + def __repr__(self): return "<PyTracer at 0x{0:0x}: {1} lines in {2} files>".format( id(self), @@ -144,9 +149,13 @@ class PyTracer(object): return if self.warn: - if sys.gettrace() != self._trace: - msg = "Trace function changed, measurement is likely wrong: %r" - self.warn(msg % (sys.gettrace(),)) + # PyPy clears the trace function before running atexit functions, + # so don't warn if we are in atexit on PyPy and the trace function + # has changed to None. + tf = sys.gettrace() + dont_warn = (env.PYPY and self.in_atexit and tf is None) + if (not dont_warn) and tf != self._trace: + self.warn("Trace function changed, measurement is likely wrong: %r" % (tf,)) sys.settrace(None) |