summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-04-04 07:08:41 -0400
committerNed Batchelder <ned@nedbatchelder.com>2017-04-04 07:08:41 -0400
commit0d82f5f090da94e4eafc83cb4cfacc2d90fc5e74 (patch)
treeac190096894b6a58e328c19206444da48e2db4c0
parente4587e795ea35931ca603d9573c4498d5276d538 (diff)
downloadpython-coveragepy-git-0d82f5f090da94e4eafc83cb4cfacc2d90fc5e74.tar.gz
Warnings can be disabled
-rw-r--r--CHANGES.rst7
-rw-r--r--coverage/config.py4
-rw-r--r--coverage/control.py4
-rw-r--r--doc/cmd.rst25
-rw-r--r--doc/config.rst6
-rw-r--r--tests/test_config.py2
-rw-r--r--tests/test_process.py18
7 files changed, 59 insertions, 7 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 1f68bd71..e5de64e1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -9,6 +9,11 @@ Change history for Coverage.py
Unreleased
----------
+- Some warnings can now be individually disabled. Warnings that can be
+ disabled have a short name appended. The ``[run] disable_warnings`` setting
+ takes a list of these warning names to disable. Closes both `issue 96`_ and
+ `issue 355`_.
+
- In previous versions, calling a method that used collected data would prevent
further collection. For example, `save()`, `report()`, `html_report()`, and
others would all stop collection. An explicit `start()` was needed to get it
@@ -28,6 +33,8 @@ Unreleased
kitted versions of coverage.py. Now it is.
.. _issue 79: https://bitbucket.org/ned/coveragepy/issues/79/save-prevents-harvesting-on-stop
+.. _issue 96: https://bitbucket.org/ned/coveragepy/issues/96/unhelpful-warnings-produced-when-using
+.. _issue 355: https://bitbucket.org/ned/coveragepy/issues/355/warnings-should-be-suppressable
.. _issue 448: https://bitbucket.org/ned/coveragepy/issues/448/save-and-html_report-prevent-further
diff --git a/coverage/config.py b/coverage/config.py
index 3dd6ea9c..3651de33 100644
--- a/coverage/config.py
+++ b/coverage/config.py
@@ -158,6 +158,7 @@ class CoverageConfig(object):
self.cover_pylib = False
self.data_file = ".coverage"
self.debug = []
+ self.disable_warnings = []
self.note = None
self.parallel = False
self.plugins = []
@@ -191,7 +192,7 @@ class CoverageConfig(object):
# Options for plugins
self.plugin_options = {}
- MUST_BE_LIST = ["omit", "include", "debug", "plugins", "concurrency"]
+ MUST_BE_LIST = ["concurrency", "debug", "disable_warnings", "include", "omit", "plugins"]
def from_args(self, **kwargs):
"""Read config values from `kwargs`."""
@@ -283,6 +284,7 @@ class CoverageConfig(object):
('cover_pylib', 'run:cover_pylib', 'boolean'),
('data_file', 'run:data_file'),
('debug', 'run:debug', 'list'),
+ ('disable_warnings', 'run:disable_warnings', 'list'),
('include', 'run:include', 'list'),
('note', 'run:note'),
('omit', 'run:omit', 'list'),
diff --git a/coverage/control.py b/coverage/control.py
index b67ed904..aeca9f71 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -608,6 +608,10 @@ class Coverage(object):
For warning suppression, use `slug` as the shorthand.
"""
+ if slug in self.config.disable_warnings:
+ # Don't issue the warning
+ return
+
self._warnings.append(msg)
if slug:
msg = "%s (%s)" % (msg, slug)
diff --git a/doc/cmd.rst b/doc/cmd.rst
index acc56d52..e9d5100b 100644
--- a/doc/cmd.rst
+++ b/doc/cmd.rst
@@ -131,40 +131,53 @@ If you are measuring coverage in a multi-process program, or across a number of
machines, you'll want the ``--parallel-mode`` switch to keep the data separate
during measurement. See :ref:`cmd_combining` below.
+
+.. _cmd_warnings:
+
+Warnings
+--------
+
During execution, coverage.py may warn you about conditions it detects that
could affect the measurement process. The possible warnings include:
-* "Trace function changed, measurement is likely wrong: XXX"
+* "Trace function changed, measurement is likely wrong: XXX (trace-changed)"
Coverage measurement depends on a Python setting called the trace function.
Other Python code in your product might change that function, which will
- disrupt coverage.py's measurement. This warning indicate that has happened.
+ disrupt coverage.py's measurement. This warning indicates that has happened.
The XXX in the message is the new trace function value, which might provide
a clue to the cause.
-* "Module XXX has no Python source"
+* "Module XXX has no Python source (module-not-python)"
You asked coverage.py to measure module XXX, but once it was imported, it
turned out not to have a corresponding .py file. Without a .py file,
coverage.py can't report on missing lines.
-* "Module XXX was never imported"
+* "Module XXX was never imported (module-not-imported)"
You asked coverage.py to measure module XXX, but it was never imported by
your program.
-* "No data was collected"
+* "No data was collected (no-data-collected)"
Coverage.py ran your program, but didn't measure any lines as executed.
This could be because you asked to measure only modules that never ran,
or for other reasons.
-* "Module XXX was previously imported, but not measured."
+* "Module XXX was previously imported, but not measured. (module-not-measured)"
You asked coverage.py to measure module XXX, but it had already been imported
when coverage started. This meant coverage.py couldn't monitor its
execution.
+Individual warnings can be disabled with the `disable_warnings
+<config_run_disable_warnings>`_ configuration setting. To silence "No data was
+collected," add this to your .coveragerc file::
+
+ [run]
+ disable_warnings = no-data-collected
+
.. _cmd_datafile:
diff --git a/doc/config.rst b/doc/config.rst
index 89493ece..0740ef1e 100644
--- a/doc/config.rst
+++ b/doc/config.rst
@@ -126,6 +126,12 @@ Before version 4.2, this option only accepted a single string.
for storing or reporting coverage. This value can include a path to another
directory.
+.. _config_run_disable_warnings:
+
+``disable_warnings`` (multi-string): a list of warnings to disable. Warnings
+that can be disabled include a short string at the end, the name of the
+warning. See :ref:`cmd_warnings` for specific warnings.
+
``debug`` (multi-string): a list of debug options. See :ref:`the run
--debug option <cmd_run_debug>` for details.
diff --git a/tests/test_config.py b/tests/test_config.py
index 2aa592b9..9224046a 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -245,6 +245,7 @@ class ConfigFileTest(CoverageTest):
plugins.a_plugin
plugins.another
debug = callers, pids , dataio
+ disable_warnings = abcd , efgh
[{section}report]
; these settings affect reporting.
@@ -325,6 +326,7 @@ class ConfigFileTest(CoverageTest):
self.assertTrue(cov.config.parallel)
self.assertEqual(cov.config.concurrency, ["thread"])
self.assertEqual(cov.config.source, ["myapp"])
+ self.assertEqual(cov.config.disable_warnings, ["abcd", "efgh"])
self.assertEqual(cov.get_exclude_list(), ["if 0:", r"pragma:?\s+no cover", "another_tab"])
self.assertTrue(cov.config.ignore_errors)
diff --git a/tests/test_process.py b/tests/test_process.py
index 237bc3c7..16341f5d 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -499,6 +499,24 @@ class ProcessTest(CoverageTest):
Coverage.py warning: No data was collected. (no-data-collected)
"""), out)
+ def test_warnings_suppressed(self):
+ self.make_file("hello.py", """\
+ import sys, os
+ print("Hello")
+ """)
+ self.make_file(".coveragerc", """\
+ [run]
+ disable_warnings = no-data-collected, module-not-imported
+ """)
+ out = self.run_command("coverage run --source=sys,xyzzy,quux hello.py")
+
+ self.assertIn("Hello\n", out)
+ self.assertIn(textwrap.dedent("""\
+ Coverage.py warning: Module sys has no Python source. (module-not-python)
+ """), out)
+ self.assertNotIn("module-not-imported", out)
+ self.assertNotIn("no-data-collected", out)
+
def test_warnings_during_reporting(self):
# While fixing issue #224, the warnings were being printed far too
# often. Make sure they're not any more.