Skip to content

Commit

Permalink
create a failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCLeduc committed Feb 8, 2021
1 parent 8176aea commit cbfffc4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
5 changes: 2 additions & 3 deletions coverage/inorout.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,8 @@ def warn_already_imported_files(self):
continue

file_path = canonical_filename(filename)
if self.omit_match and self.omit_match.match(file_path):
continue

# if self.omit_match and self.omit_match.match(file_path):
# continue

disp = self.should_trace(filename)
if disp.trace:
Expand Down
69 changes: 38 additions & 31 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,37 +253,6 @@ def coverage_init(reg, options):
out = self.run_command("coverage html")
self.assertEqual(out, "")

def test_omitted_traced_plugin_deps_dont_warn(self):
self.make_file("traces_own_deps_plugin.py", """\
from coverage import CoveragePlugin
import local_module
class MyPlugin(CoveragePlugin):
def file_tracer(self, filename):
if 'local_module' in filename:
return self
return None
def coverage_init(reg, options):
reg.add_noop(MyPlugin())
""")
self.make_file("local_module.py", "CONST = 1")
self.make_file(".coveragerc", """\
[run]
plugins = traces_own_deps_plugin
omit=local_module.py,traces_own_deps_plugin.py
source=.
""")
self.make_file("main_file.py", """\
import local_module
print('MAIN')
""")

out = self.run_command("coverage run main_file.py")
self.assertEqual(out, "MAIN\n")
out = self.run_command("coverage html")
self.assertEqual(out, "")


class PluginWarningOnPyTracer(CoverageTest):
"""Test that we get a controlled exception with plugins on PyTracer."""
def test_exception_if_plugins_on_pytracer(self):
Expand Down Expand Up @@ -609,6 +578,44 @@ def coverage_init(reg, options):
cov.analysis("fictional.py")


def test_omitted_traced_plugin_deps_dont_warn(self):
self.make_file("traces_own_deps_plugin.py", """\
from coverage.plugin import CoveragePlugin, FileTracer
import local_module
class MyPlugin(CoveragePlugin,FileTracer):
def file_tracer(self, filename):
if 'local_module' in filename:
return self
return None
def has_dynamic_source_filename(self):
return True
def dynamic_source_filename(self, filename, frame):
return filename
def coverage_init(reg, options):
reg.add_file_tracer(MyPlugin())
""")
self.make_file("local_module.py", "CONST = 1")
self.make_file(".coveragerc", """\
[run]
plugins = traces_own_deps_plugin
omit=local_module.py,traces_own_deps_plugin.py
source=.
""")
self.make_file("main_file.py", """\
import local_module
print('MAIN')
""")

out = self.run_command("coverage run main_file.py")
self.assertEqual(out, "MAIN\n")
out = self.run_command("coverage html")
self.assertEqual(out, "")


class BadFileTracerTest(FileTracerTest):
"""Test error handling around file tracer plugins."""

Expand Down

0 comments on commit cbfffc4

Please sign in to comment.