Skip to content

Commit

Permalink
issue 1496 - xfail with condition keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
tomviner committed Apr 19, 2016
1 parent 6a3c943 commit b8614a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion _pytest/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import pytest
from _pytest.mark import MarkInfo, MarkDecorator

MISSING = object()


def pytest_addoption(parser):
group = parser.getgroup("general")
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('''
Expand Down

0 comments on commit b8614a4

Please sign in to comment.