summaryrefslogtreecommitdiff
path: root/coverage/control.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-04-03 09:54:37 -0400
committerNed Batchelder <ned@nedbatchelder.com>2017-04-03 09:54:37 -0400
commit2f01ede8dd7eeb8f59db533921afd6ff56ff6acb (patch)
tree1c4f09c3bafed851adcc0719b87606f076058120 /coverage/control.py
parentffe71f0660e05abcc8c26aa91899e08242d968c1 (diff)
downloadpython-coveragepy-2f01ede8dd7eeb8f59db533921afd6ff56ff6acb.tar.gz
Add slugs to warnings in prep for suppressable warnings
Diffstat (limited to 'coverage/control.py')
-rw-r--r--coverage/control.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/coverage/control.py b/coverage/control.py
index fd9384e..b67ed90 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: