Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/4497.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the crash that occurred when pytest was invoked with `-o empty_parameter_set_mark=xfail` + `--runxfail`
2 changes: 1 addition & 1 deletion src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def fillfixtures(function):


def get_direct_param_fixture_func(request):
return request.param
return request.param if hasattr(request, "param") else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that change makes the fixture helper incorrect - if no parameter is existing this one has to raise a failure - the tests shouldnt even run however

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this raise an error then, or perhaps pytest.fail("no direct parameter")??



@attr.s(slots=True)
Expand Down
35 changes: 35 additions & 0 deletions testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,41 @@ def test_foo():
result.stdout.fnmatch_lines(["*1 passed*"])
assert result.ret == 0

@pytest.mark.parametrize("strict", [True, False])
def test_runxfail_with_empty_parameter_set_mark_xfail(self, testdir, strict):
testdir.makeini(
"""
[pytest]
xfail_strict = %s
"""
% strict
)

p = testdir.makepyfile(
"""
import pytest

@pytest.mark.parametrize(
('a', 'b'),
# no cases defined yet
(
),
)
def test(a, b):
assert 1 == 1
"""
)
result = testdir.runpytest(
p, "--runxfail", "-o", "empty_parameter_set_mark=xfail"
)

result.stdout.fnmatch_lines(["*1 failed*" if strict else "*1 passed*"])
if strict:
result.stdout.fnmatch_lines(
["*XPASS(strict)] got empty parameter set ('a', 'b')*"]
)
assert result.ret == (1 if strict else 0)

@pytest.mark.parametrize("strict_val", ["true", "false"])
def test_strict_xfail_default_from_file(self, testdir, strict_val):
testdir.makeini(
Expand Down