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 | |
parent | 0ea46fc3a14eff7ee483513a0f72240c808c046c (diff) | |
download | python-coveragepy-git-e4587e795ea35931ca603d9573c4498d5276d538.tar.gz |
Add slugs to warnings in prep for suppressable warnings
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/control.py | 20 | ||||
-rw-r--r-- | coverage/pytracer.py | 5 |
2 files changed, 18 insertions, 7 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) |