Skip to content

Commit 99c4b6f

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

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _istrue(self):
120120
return self.result
121121
if self.holder:
122122
d = self._getglobals()
123-
if self.holder.args:
123+
if self.holder.args or 'condition' in self.holder.kwargs:
124124
self.result = False
125125
# "holder" might be a MarkInfo or a MarkDecorator; only
126126
# MarkInfo keeps track of all parameters it received in an
@@ -130,6 +130,8 @@ def _istrue(self):
130130
else:
131131
arglist = [(self.holder.args, self.holder.kwargs)]
132132
for args, kwargs in arglist:
133+
if 'condition' in kwargs:
134+
args = (kwargs['condition'],)
133135
for expr in args:
134136
self.expr = expr
135137
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)