From 093d92d31ba44c854873767d28c03b797d913c17 Mon Sep 17 00:00:00 2001 From: Krassimir Valev Date: Tue, 19 Jan 2021 16:02:05 +0200 Subject: [PATCH] Support regex patterns in module names --- coverage/files.py | 3 ++- tests/test_files.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/coverage/files.py b/coverage/files.py index 59b2bd61d..468d442eb 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -242,6 +242,7 @@ class ModuleMatcher(object): """A matcher for modules in a tree.""" def __init__(self, module_names): self.modules = list(module_names) + self.pattern = fnmatches_to_regex(module_names) def __repr__(self): return "" % (self.modules) @@ -263,7 +264,7 @@ def match(self, module_name): # This is a module in the package return True - return False + return bool(self.pattern.match(module_name)) class FnmatchMatcher(object): diff --git a/tests/test_files.py b/tests/test_files.py index 84e25f107..673a955ad 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -187,8 +187,12 @@ def test_module_matcher(self): ('__main__', False), ('mymain', True), ('yourmain', False), + ('pkg', True), + ('pkg.main', True), + ('pkg2', True), + ('apkg', False), ] - modules = ['test', 'py.test', 'mymain'] + modules = ['test', 'py.test', 'mymain', 'pkg*'] mm = ModuleMatcher(modules) self.assertEqual( mm.info(),