diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2017-04-03 09:54:37 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2017-04-03 09:54:37 -0400 |
commit | e4587e795ea35931ca603d9573c4498d5276d538 (patch) | |
tree | 74e1d2c2e70c55062796e676dfc40909ec3b8706 /coverage/control.py | |
parent | 0ea46fc3a14eff7ee483513a0f72240c808c046c (diff) | |
download | python-coveragepy-git-e4587e795ea35931ca603d9573c4498d5276d538.tar.gz |
Add slugs to warnings in prep for suppressable warnings
Diffstat (limited to 'coverage/control.py')
-rw-r--r-- | coverage/control.py | 20 |
1 files changed, 14 insertions, 6 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: |