Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support regex patterns in module names #1104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion coverage/files.py
Expand Up @@ -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 "<ModuleMatcher %r>" % (self.modules)
Expand All @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion tests/test_files.py
Expand Up @@ -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(),
Expand Down