diff options
-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) |