Skip to content

Commit 1b95739

Browse files
committed
issue 1496 - xfail with condition keyword
1 parent 6a3c943 commit 1b95739

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
**Bug Fixes**
55

6-
*
6+
* Fix Xfail does not work with condition keyword argument.
7+
Thanks `@astraw38`_ for reporting the issue (`#1496`_) and `@tomviner`_
8+
for PR the (`#1524`_).
79

810
*
911

@@ -20,8 +22,11 @@
2022

2123

2224
.. _#1506: https://github.com/pytest-dev/pytest/pull/1506
25+
.. _#1496: https://github.com/pytest-dev/pytest/issue/1496
26+
.. _#1524: https://github.com/pytest-dev/pytest/issue/1524
2327

2428
.. _@prusse-martin: https://github.com/prusse-martin
29+
.. _@astraw38: https://github.com/astraw38
2530

2631

2732
2.9.1

_pytest/skipping.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import pytest
88
from _pytest.mark import MarkInfo, MarkDecorator
99

10+
MISSING = object()
11+
1012

1113
def pytest_addoption(parser):
1214
group = parser.getgroup("general")
@@ -120,7 +122,7 @@ def _istrue(self):
120122
return self.result
121123
if self.holder:
122124
d = self._getglobals()
123-
if self.holder.args:
125+
if self.holder.args or 'condition' in self.holder.kwargs:
124126
self.result = False
125127
# "holder" might be a MarkInfo or a MarkDecorator; only
126128
# MarkInfo keeps track of all parameters it received in an
@@ -130,6 +132,9 @@ def _istrue(self):
130132
else:
131133
arglist = [(self.holder.args, self.holder.kwargs)]
132134
for args, kwargs in arglist:
135+
condition = kwargs.get('condition', MISSING)
136+
if condition is not MISSING:
137+
args = (condition,)
133138
for expr in args:
134139
self.expr = expr
135140
if isinstance(expr, py.builtin._basestring):

testing/test_skipping.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,19 @@ def test_foo():
405405
result.stdout.fnmatch_lines('*1 passed*')
406406
assert result.ret == 0
407407

408+
@pytest.mark.parametrize('strict', [True, False])
409+
def test_xfail_condition_keyword(self, testdir, strict):
410+
p = testdir.makepyfile("""
411+
import pytest
412+
413+
@pytest.mark.xfail(condition=False, reason='unsupported feature', strict=%s)
414+
def test_foo():
415+
pass
416+
""" % strict)
417+
result = testdir.runpytest(p, '-rxX')
418+
result.stdout.fnmatch_lines('*1 passed*')
419+
assert result.ret == 0
420+
408421
@pytest.mark.parametrize('strict_val', ['true', 'false'])
409422
def test_strict_xfail_default_from_file(self, testdir, strict_val):
410423
testdir.makeini('''

0 commit comments

Comments
 (0)