support usefixtures with parametrize
This commit is contained in:
parent
241f2a890e
commit
47c76694f8
|
@ -507,7 +507,7 @@ class PyCollector(PyobjMixin, nodes.Collector):
|
|||
|
||||
for callspec in metafunc._calls:
|
||||
subname = f"{name}[{callspec.id}]"
|
||||
yield Function.from_parent(
|
||||
node = Function.from_parent(
|
||||
self,
|
||||
name=subname,
|
||||
callspec=callspec,
|
||||
|
@ -515,6 +515,18 @@ class PyCollector(PyobjMixin, nodes.Collector):
|
|||
keywords={callspec.id: True},
|
||||
originalname=name,
|
||||
)
|
||||
# if usefixtures is added via a parameter, then there will be
|
||||
# fixtures missing from the node.fixturenames
|
||||
callspec_usefixtures = tuple(
|
||||
arg
|
||||
for mark in node.iter_markers(name="usefixtures")
|
||||
for arg in mark.args
|
||||
if arg not in node.fixturenames
|
||||
)
|
||||
if callspec_usefixtures:
|
||||
# node.fixturenames must be unique for this parameter
|
||||
node.fixturenames = [*node.fixturenames, *callspec_usefixtures]
|
||||
yield node
|
||||
|
||||
|
||||
def importtestmodule(
|
||||
|
|
|
@ -2112,3 +2112,31 @@ class TestMarkersWithParametrization:
|
|||
"*= 6 passed in *",
|
||||
]
|
||||
)
|
||||
|
||||
def test_simple_usefixtures_single_argname(self, pytester: Pytester) -> None:
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def some_fixture():
|
||||
pytest.skip()
|
||||
|
||||
@pytest.mark.parametrize("val", [
|
||||
1,
|
||||
pytest.param(2, marks=pytest.mark.usefixtures('some_fixture')),
|
||||
3,
|
||||
])
|
||||
def test_foo(request, val):
|
||||
assert val
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest("-vv", "-s")
|
||||
result.assert_outcomes(passed=2, skipped=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"test_simple_usefixtures_single_argname.py::test_foo[1] PASSED",
|
||||
"test_simple_usefixtures_single_argname.py::test_foo[2] SKIPPED",
|
||||
"test_simple_usefixtures_single_argname.py::test_foo[3] PASSED",
|
||||
]
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue