summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-12-30 12:30:09 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-12-30 12:30:09 -0500
commit8a21afc5658e4337571563cf574e9fef58c6683e (patch)
treeab689b2d470bbd9cf85a61461b84b3690d3214bb
parent179db49d02eaa4d92d367000170e7fd70bf816d3 (diff)
downloadpython-coveragepy-8a21afc5658e4337571563cf574e9fef58c6683e.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.
-rw-r--r--CHANGES.rst4
-rw-r--r--coverage/pytracer.py15
2 files changed, 16 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index d502612..e9c32fb 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 23f4946..13a3b0c 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)