summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/collector.py6
-rw-r--r--coverage/misc.py6
-rw-r--r--setup.py2
-rw-r--r--test/test_farm.py6
4 files changed, 16 insertions, 4 deletions
diff --git a/coverage/collector.py b/coverage/collector.py
index 1b807b27..bf465939 100644
--- a/coverage/collector.py
+++ b/coverage/collector.py
@@ -2,6 +2,8 @@
import os, sys, threading
+from coverage.misc import short_stack
+
try:
# Use the C extension code when we can, for speed.
from coverage.tracer import CTracer # pylint: disable=F0401,E0611
@@ -124,8 +126,8 @@ class PyTracer(object):
"""Stop this Tracer."""
if hasattr(sys, "gettrace") and self.warn:
if sys.gettrace() != self._trace:
- msg = "Trace function changed, measurement is likely wrong: %r"
- self.warn(msg % sys.gettrace())
+ msg = "Trace function changed, measurement is likely wrong: %r\n%s"
+ self.warn(msg % (sys.gettrace(), short_stack()))
sys.settrace(None)
def get_stats(self):
diff --git a/coverage/misc.py b/coverage/misc.py
index 3ed854a7..b4d1c833 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -54,6 +54,12 @@ def format_lines(statements, lines):
return ret
+def short_stack():
+ """Return a string summarizing the call stack."""
+ stack = inspect.stack()[:0:-1]
+ return "\n".join("%30s : %s @%d" % (t[3],t[1],t[2]) for t in stack)
+
+
def expensive(fn):
"""A decorator to cache the result of an expensive operation.
diff --git a/setup.py b/setup.py
index 53f08f9b..62db5e7b 100644
--- a/setup.py
+++ b/setup.py
@@ -121,7 +121,7 @@ if sys.platform == 'win32' and sys.version_info > (2, 6):
class BuildFailed(Exception):
"""Raise this to indicate the C extension wouldn't build."""
def __init__(self):
- Exception.__init__()
+ Exception.__init__(self)
self.cause = sys.exc_info()[1] # work around py 2/3 different syntax
class ve_build_ext(build_ext.build_ext):
diff --git a/test/test_farm.py b/test/test_farm.py
index 5a2cf8a8..418a3cf5 100644
--- a/test/test_farm.py
+++ b/test/test_farm.py
@@ -7,6 +7,7 @@ sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
from backtest import run_command, execfile # pylint: disable=W0622
from coverage.control import _TEST_NAME_FILE
+from coverage.misc import short_stack
def test_farm(clean_only=False):
@@ -93,7 +94,10 @@ class FarmTestCase(object):
self.cd(cwd)
# Remove any new modules imported during the test run. This lets us
# import the same source files for more than one test.
- for m in [m for m in sys.modules if m not in old_mods]:
+ to_del = [m for m in sys.modules if m not in old_mods]
+ with open(r"\foo\cov.txt", "a") as f:
+ print >>f, ("Deleting modules: %s, %r\n%s" % (self.description, to_del, short_stack()))
+ for m in to_del:
del sys.modules[m]
def run_fully(self): # pragma: not covered