Don't define pytest_bdd_apply_tag when frozen

This should help with the undefined hook while not requiring to install
the pytest-bdd plugin when frozen.
This commit is contained in:
Florian Bruhin 2016-06-30 17:40:54 +02:00
parent 49d3e9ece8
commit ead437be82

View File

@ -187,41 +187,42 @@ def pytest_sessionfinish(exitstatus):
f.write(str(exitstatus)) f.write(str(exitstatus))
def pytest_bdd_apply_tag(tag, function): if not getattr(sys, 'frozen', False):
version_re = re.compile(r""" def pytest_bdd_apply_tag(tag, function):
(?P<package>qt|pyqt) version_re = re.compile(r"""
(?P<operator>==|>|>=|<|<=|!=) (?P<package>qt|pyqt)
(?P<version>\d+\.\d+\.\d+) (?P<operator>==|>|>=|<|<=|!=)
""", re.VERBOSE) (?P<version>\d+\.\d+\.\d+)
""", re.VERBOSE)
match = version_re.match(tag) match = version_re.match(tag)
if not match: if not match:
# Use normal tag mapping # Use normal tag mapping
return None return None
operators = { operators = {
'==': operator.eq, '==': operator.eq,
'>': operator.gt, '>': operator.gt,
'<': operator.lt, '<': operator.lt,
'>=': operator.ge, '>=': operator.ge,
'<=': operator.le, '<=': operator.le,
'!=': operator.ne, '!=': operator.ne,
} }
package = match.group('package') package = match.group('package')
op = operators[match.group('operator')] op = operators[match.group('operator')]
version = match.group('version') version = match.group('version')
if package == 'qt': if package == 'qt':
mark = pytest.mark.skipif(qtutils.version_check(version, op), mark = pytest.mark.skipif(qtutils.version_check(version, op),
reason='Needs ' + tag) reason='Needs ' + tag)
elif package == 'pyqt': elif package == 'pyqt':
major, minor, patch = [int(e) for e in version.split('.')] major, minor, patch = [int(e) for e in version.split('.')]
hex_version = (major << 16) | (minor << 8) | patch hex_version = (major << 16) | (minor << 8) | patch
mark = pytest.mark.skipif(not op(PYQT_VERSION, hex_version), mark = pytest.mark.skipif(not op(PYQT_VERSION, hex_version),
reason='Needs ' + tag) reason='Needs ' + tag)
else: else:
raise ValueError("Invalid package {!r}".format(package)) raise ValueError("Invalid package {!r}".format(package))
mark(function) mark(function)
return True return True