Skip to content

Commit d35e8c4

Browse files
committedJan 30, 2022
debug: better tracing of pytracer changed
1 parent ea71ae9 commit d35e8c4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed
 

‎coverage/pytracer.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self):
6868
atexit.register(setattr, self, 'in_atexit', True)
6969

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

273275
def activity(self):
274276
"""Has there been any activity?"""

‎tests/test_oddball.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""Oddball cases for testing coverage.py"""
55

66
import os.path
7+
import re
78
import sys
89

910
from flaky import flaky
@@ -132,7 +133,13 @@ def recur(n):
132133

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

0 commit comments

Comments
 (0)
Please sign in to comment.