checking that option contains glob characters before calling fnmatch

requested during code review

--HG--
branch : python-classes-glob
This commit is contained in:
Bruno Oliveira 2014-10-20 18:36:31 -02:00
parent b928928942
commit 0b620c304b
1 changed files with 5 additions and 1 deletions

View File

@ -322,7 +322,11 @@ class PyCollector(PyobjMixin, pytest.Collector):
for option in self.config.getini(option_name):
if name.startswith(option):
return True
elif fnmatch.fnmatch(name, option):
# check that name looks like a glob-string before calling fnmatch
# because this is called for every name in each collected module,
# and fnmatch is somewhat expensive to call
elif ('*' in option or '?' in option or '[' in option) and \
fnmatch.fnmatch(name, option):
return True
return False