From 3dccd156631532f068c129f1e303648e0e970c09 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 18 Aug 2016 17:41:34 +0200 Subject: [PATCH] bdd: Handle @qtwebengine_todo tags --- tests/conftest.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e6fff31ae..801b699a2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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""" (?Pqt|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