summaryrefslogtreecommitdiff
path: root/tests/test_plugins.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2020-09-13 15:47:15 -0400
committerNed Batchelder <ned@nedbatchelder.com>2020-09-13 15:48:56 -0400
commit039ef0959c3f21fe0991204c19fb99fab14055f5 (patch)
tree3058128babbc49c88618e696ea28d35445f5763f /tests/test_plugins.py
parent24eb6fdc8495f969ffeb724f2e96d3941442dd2d (diff)
downloadpython-coveragepy-git-039ef0959c3f21fe0991204c19fb99fab14055f5.tar.gz
If a plugin is disabled, don't try to record its file tracers. #1011
Diffstat (limited to 'tests/test_plugins.py')
-rw-r--r--tests/test_plugins.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index ed58c5f4..6340f9c3 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -611,6 +611,7 @@ class BadFileTracerTest(FileTracerTest):
cov = coverage.Coverage()
cov.set_option("run:plugins", [module_name])
self.start_import_stop(cov, "simple")
+ cov.save() # pytest-cov does a save after stop, so we'll do it too.
return cov
def run_bad_plugin(self, module_name, plugin_name, our_error=True, excmsg=None, excmsgs=None):
@@ -715,6 +716,37 @@ class BadFileTracerTest(FileTracerTest):
""")
self.run_bad_plugin("bad_plugin", "Plugin")
+ def test_file_tracer_fails_eventually(self):
+ # Django coverage plugin can report on a few files and then fail.
+ # https://github.com/nedbat/coveragepy/issues/1011
+ self.make_file("bad_plugin.py", """\
+ import os.path
+ import coverage.plugin
+ class Plugin(coverage.plugin.CoveragePlugin):
+ def __init__(self):
+ self.calls = 0
+
+ def file_tracer(self, filename):
+ print(filename)
+ self.calls += 1
+ if self.calls <= 2:
+ return FileTracer(filename)
+ else:
+ 17/0 # Oh noes!
+
+ class FileTracer(coverage.FileTracer):
+ def __init__(self, filename):
+ self.filename = filename
+ def source_filename(self):
+ return os.path.basename(self.filename).replace(".py", ".foo")
+ def line_number_range(self, frame):
+ return -1, -1
+
+ def coverage_init(reg, options):
+ reg.add_file_tracer(Plugin())
+ """)
+ self.run_bad_plugin("bad_plugin", "Plugin")
+
def test_file_tracer_returns_wrong(self):
self.make_file("bad_plugin.py", """\
import coverage.plugin