From b8614a426a9c9f750b70e98478523e617faabee5 Mon Sep 17 00:00:00 2001 From: TomV Date: Tue, 19 Apr 2016 15:21:19 +0100 Subject: [PATCH] issue 1496 - xfail with condition keyword --- _pytest/skipping.py | 7 ++++++- testing/test_skipping.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/_pytest/skipping.py b/_pytest/skipping.py index 55a24ddb9df..9c7469b6c0b 100644 --- a/_pytest/skipping.py +++ b/_pytest/skipping.py @@ -7,6 +7,8 @@ import pytest from _pytest.mark import MarkInfo, MarkDecorator +MISSING = object() + def pytest_addoption(parser): group = parser.getgroup("general") @@ -120,7 +122,7 @@ def _istrue(self): return self.result if self.holder: d = self._getglobals() - if self.holder.args: + if self.holder.args or 'condition' in self.holder.kwargs: self.result = False # "holder" might be a MarkInfo or a MarkDecorator; only # MarkInfo keeps track of all parameters it received in an @@ -130,6 +132,9 @@ def _istrue(self): else: arglist = [(self.holder.args, self.holder.kwargs)] for args, kwargs in arglist: + condition = kwargs.get('condition', MISSING) + if condition is not MISSING: + args = (condition,) for expr in args: self.expr = expr if isinstance(expr, py.builtin._basestring): diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 194c8692b90..2bfb6a8dc58 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -405,6 +405,19 @@ def test_foo(): result.stdout.fnmatch_lines('*1 passed*') assert result.ret == 0 + @pytest.mark.parametrize('strict', [True, False]) + def test_xfail_condition_keyword(self, testdir, strict): + p = testdir.makepyfile(""" + import pytest + + @pytest.mark.xfail(condition=False, reason='unsupported feature', strict=%s) + def test_foo(): + pass + """ % strict) + result = testdir.runpytest(p, '-rxX') + result.stdout.fnmatch_lines('*1 passed*') + assert result.ret == 0 + @pytest.mark.parametrize('strict_val', ['true', 'false']) def test_strict_xfail_default_from_file(self, testdir, strict_val): testdir.makeini('''