Skip to content

Commit

Permalink
debug: better tracing of pytracer changed
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 30, 2022
1 parent ea71ae9 commit d35e8c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 5 additions & 3 deletions coverage/pytracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self):
atexit.register(setattr, self, 'in_atexit', True)

def __repr__(self):
return "<PyTracer at {}: {} lines in {} files>".format(
return "<PyTracer at 0x{:x}: {} lines in {} files>".format(
id(self),
sum(len(v) for v in self.data.values()),
len(self.data),
Expand Down Expand Up @@ -267,8 +267,10 @@ def stop(self):
# has changed to None.
dont_warn = (env.PYPY and env.PYPYVERSION >= (5, 4) and self.in_atexit and tf is None)
if (not dont_warn) and tf != self._trace: # pylint: disable=comparison-with-callable
msg = f"Trace function changed, measurement is likely wrong: {tf!r}"
self.warn(msg, slug="trace-changed")
self.warn(
f"Trace function changed, data is likely wrong: {tf!r} != {self._trace!r}",
slug="trace-changed",
)

def activity(self):
"""Has there been any activity?"""
Expand Down
9 changes: 8 additions & 1 deletion tests/test_oddball.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Oddball cases for testing coverage.py"""

import os.path
import re
import sys

from flaky import flaky
Expand Down Expand Up @@ -132,7 +133,13 @@ def recur(n):

# Get a warning about the stackoverflow effect on the tracing function.
if pytrace: # pragma: no metacov
assert cov._warnings == ["Trace function changed, measurement is likely wrong: None"]
assert len(cov._warnings) == 1
assert re.fullmatch(
r"Trace function changed, data is likely wrong: None != " +
r"<bound method PyTracer._trace of " +
"<PyTracer at 0x[0-9a-fA-F]+: 5 lines in 1 files>>",
cov._warnings[0],
)
else:
assert not cov._warnings

Expand Down

0 comments on commit d35e8c4

Please sign in to comment.