bdd: Handle @qtwebengine_todo tags

This commit is contained in:
Florian Bruhin 2016-08-18 17:41:34 +02:00
parent 745614e45d
commit 3dccd15663

View File

@ -184,13 +184,12 @@ def pytest_sessionfinish(exitstatus):
if not getattr(sys, 'frozen', False):
def pytest_bdd_apply_tag(tag, function):
def _get_version_tag(tag):
"""Handle tags like pyqt>=5.3.1 for BDD tests.
This transforms e.g. pyqt>=5.3.1 into an appropriate @pytest.mark.skip
marker, and falls back to pytest-bdd's implementation for all other
casesinto an appropriate @pytest.mark.skip marker, and falls back to
pytest-bdd's implementation for all other cases
"""
version_re = re.compile(r"""
(?P<package>qt|pyqt)
@ -200,7 +199,6 @@ if not getattr(sys, 'frozen', False):
match = version_re.match(tag)
if not match:
# Use normal tag mapping
return None
operators = {
@ -217,15 +215,33 @@ if not getattr(sys, 'frozen', False):
version = match.group('version')
if package == 'qt':
mark = pytest.mark.skipif(qtutils.version_check(version, op),
return pytest.mark.skipif(qtutils.version_check(version, op),
reason='Needs ' + tag)
elif package == 'pyqt':
major, minor, patch = [int(e) for e in version.split('.')]
hex_version = (major << 16) | (minor << 8) | patch
mark = pytest.mark.skipif(not op(PYQT_VERSION, hex_version),
return pytest.mark.skipif(not op(PYQT_VERSION, hex_version),
reason='Needs ' + tag)
else:
raise ValueError("Invalid package {!r}".format(package))
mark(function)
return True
def _get_qtwebengine_tag(tag):
"""Handle a @qtwebengine_todo tag."""
if not tag.startswith('qtwebengine_todo:'):
return None
desc = tag.split(':', maxsplit=1)[1]
return pytest.mark.qtwebengine_todo(desc)
def pytest_bdd_apply_tag(tag, function):
"""Handle custom tags for BDD tests.
This tries various functions, and if none knows how to handle this tag,
it returns None so it falls back to pytest-bdd's implementation.
"""
funcs = [_get_version_tag, _get_qtwebengine_tag]
for func in funcs:
mark = func(tag)
if mark is not None:
mark(function)
return True
return None