summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-01-06 17:06:59 -0500
committerNed Batchelder <ned@nedbatchelder.com>2018-01-06 17:06:59 -0500
commitdb260dc3feb931947309e88fa93063a0a37b6eda (patch)
tree50867f9cd23e2c6196f145eca32e39cd0ffdbe19 /tests
parent66dc96690399b6db97c638fefa8dcff626844900 (diff)
downloadpython-coveragepy-db260dc3feb931947309e88fa93063a0a37b6eda.tar.gz
A new kind of plug-in: configurers. #563
Diffstat (limited to 'tests')
-rw-r--r--tests/plugin_config.py22
-rw-r--r--tests/test_plugins.py19
2 files changed, 38 insertions, 3 deletions
diff --git a/tests/plugin_config.py b/tests/plugin_config.py
new file mode 100644
index 0000000..67a790a
--- /dev/null
+++ b/tests/plugin_config.py
@@ -0,0 +1,22 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+"""A configuring plugin for test_plugins.py to import."""
+
+import coverage
+
+
+class Plugin(coverage.CoveragePlugin):
+ """A configuring plugin for testing."""
+ def configure(self, config):
+ """Configure all the things!"""
+ opt_name = "report:exclude_lines"
+ exclude_lines = config.get_option(opt_name)
+ exclude_lines.append(r"pragma: custom")
+ exclude_lines.append(r"pragma: or whatever")
+ config.set_option(opt_name, exclude_lines)
+
+
+def coverage_init(reg, options): # pylint: disable=unused-argument
+ """Called by coverage to initialize the plugins here."""
+ reg.add_configurer(Plugin())
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index 4dfe0bd..c4fc3ac 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -621,10 +621,10 @@ class BadFileTracerTest(FileTracerTest):
# There should be a warning explaining what's happening, but only one.
# The message can be in two forms:
- # Disabling plugin '...' due to previous exception
+ # Disabling plug-in '...' due to previous exception
# or:
- # Disabling plugin '...' due to an exception:
- msg = "Disabling plugin '%s.%s' due to " % (module_name, plugin_name)
+ # Disabling plug-in '...' due to an exception:
+ msg = "Disabling plug-in '%s.%s' due to " % (module_name, plugin_name)
warnings = stderr.count(msg)
self.assertEqual(warnings, 1)
@@ -848,3 +848,16 @@ class BadFileTracerTest(FileTracerTest):
self.run_bad_plugin(
"bad_plugin", "Plugin", our_error=False, excmsg="an integer is required",
)
+
+
+class ConfigurerPluginTest(CoverageTest):
+ """Test configuring plugins."""
+
+ def test_configurer_plugin(self):
+ cov = coverage.Coverage()
+ cov.set_option("run:plugins", ["tests.plugin_config"])
+ cov.start()
+ cov.stop() # pragma: nested
+ excluded = cov.get_option("report:exclude_lines")
+ self.assertIn("pragma: custom", excluded)
+ self.assertIn("pragma: or whatever", excluded)