From 0b620c304bc5c55fa5ca8842173539487ee71f68 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 20 Oct 2014 18:36:31 -0200 Subject: [PATCH] checking that option contains glob characters before calling fnmatch requested during code review --HG-- branch : python-classes-glob --- _pytest/python.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/_pytest/python.py b/_pytest/python.py index 0160b18ae..ed3443e9e 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -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