summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/control.py20
-rw-r--r--coverage/pytracer.py5
-rw-r--r--tests/coveragetest.py2
-rw-r--r--tests/test_process.py11
4 files changed, 25 insertions, 13 deletions
diff --git a/coverage/control.py b/coverage/control.py
index fd9384e0..b67ed904 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -603,9 +603,14 @@ class Coverage(object):
return not reason
- def _warn(self, msg):
- """Use `msg` as a warning."""
+ def _warn(self, msg, slug=None):
+ """Use `msg` as a warning.
+
+ For warning suppression, use `slug` as the shorthand.
+ """
self._warnings.append(msg)
+ if slug:
+ msg = "%s (%s)" % (msg, slug)
if self.debug.should('pid'):
msg = "[%d] %s" % (os.getpid(), msg)
sys.stderr.write("Coverage.py warning: %s\n" % msg)
@@ -829,18 +834,21 @@ class Coverage(object):
if self._warn_unimported_source:
for pkg in self.source_pkgs_unmatched:
if pkg not in sys.modules:
- self._warn("Module %s was never imported." % pkg)
+ self._warn("Module %s was never imported." % pkg, slug="module-not-imported")
elif not (
hasattr(sys.modules[pkg], '__file__') and
os.path.exists(sys.modules[pkg].__file__)
):
- self._warn("Module %s has no Python source." % pkg)
+ self._warn("Module %s has no Python source." % pkg, slug="module-not-python")
else:
- self._warn("Module %s was previously imported, but not measured." % pkg)
+ self._warn(
+ "Module %s was previously imported, but not measured." % pkg,
+ slug="module-not-measured",
+ )
# Find out if we got any data.
if not self.data and self._warn_no_data:
- self._warn("No data was collected.")
+ self._warn("No data was collected.", slug="no-data-collected")
# Find files that were never executed at all.
for pkg in self.source_pkgs:
diff --git a/coverage/pytracer.py b/coverage/pytracer.py
index 6dae0148..b41f4059 100644
--- a/coverage/pytracer.py
+++ b/coverage/pytracer.py
@@ -166,7 +166,10 @@ class PyTracer(object):
tf = sys.gettrace()
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:
- self.warn("Trace function changed, measurement is likely wrong: %r" % (tf,))
+ self.warn(
+ "Trace function changed, measurement is likely wrong: %r" % (tf,),
+ slug="trace-changed",
+ )
sys.settrace(None)
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 28ee92e7..7fcc9f9b 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -284,7 +284,7 @@ class CoverageTest(
"""
saved_warnings = []
- def capture_warning(msg):
+ def capture_warning(msg, slug=None): # pylint: disable=unused-argument
"""A fake implementation of Coverage._warn, to capture warnings."""
saved_warnings.append(msg)
diff --git a/tests/test_process.py b/tests/test_process.py
index 2ecc9122..237bc3c7 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -493,10 +493,10 @@ class ProcessTest(CoverageTest):
self.assertIn("Hello\n", out)
self.assertIn(textwrap.dedent("""\
- Coverage.py warning: Module sys has no Python source.
- Coverage.py warning: Module xyzzy was never imported.
- Coverage.py warning: Module quux was never imported.
- Coverage.py warning: No data was collected.
+ Coverage.py warning: Module sys has no Python source. (module-not-python)
+ Coverage.py warning: Module xyzzy was never imported. (module-not-imported)
+ Coverage.py warning: Module quux was never imported. (module-not-imported)
+ Coverage.py warning: No data was collected. (no-data-collected)
"""), out)
def test_warnings_during_reporting(self):
@@ -663,7 +663,8 @@ class ProcessTest(CoverageTest):
out = self.run_command("python run_twice.py")
self.assertEqual(
out,
- "Coverage.py warning: Module foo was previously imported, but not measured.\n"
+ "Coverage.py warning: Module foo was previously imported, but not measured. "
+ "(module-not-measured)\n"
)
def test_module_name(self):