mirror of https://github.com/pytest-dev/pytest.git
Prohibit pytest.mark.usefixtures in pytest.param (#12828)
Mitigates #4112 a bit. Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
This commit is contained in:
parent
fb740251fe
commit
23256dd967
1
AUTHORS
1
AUTHORS
|
@ -95,6 +95,7 @@ Christine Mecklenborg
|
|||
Christoph Buelter
|
||||
Christopher Dignam
|
||||
Christopher Gilling
|
||||
Christopher Head
|
||||
Claire Cecil
|
||||
Claudio Madotto
|
||||
Clément M.T. Robert
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Using :ref:`pytest.mark.usefixtures <pytest.mark.usefixtures ref>` on :func:`pytest.param` now produces an error instead of silently doing nothing.
|
|
@ -66,7 +66,12 @@ def param(
|
|||
assert eval(test_input) == expected
|
||||
|
||||
:param values: Variable args of the values of the parameter set, in order.
|
||||
:param marks: A single mark or a list of marks to be applied to this parameter set.
|
||||
|
||||
:param marks:
|
||||
A single mark or a list of marks to be applied to this parameter set.
|
||||
|
||||
:ref:`pytest.mark.usefixtures <pytest.mark.usefixtures ref>` cannot be added via this parameter.
|
||||
|
||||
:param id: The id to attribute to this parameter set.
|
||||
"""
|
||||
return ParameterSet.param(*values, marks=marks, id=id)
|
||||
|
|
|
@ -88,6 +88,11 @@ class ParameterSet(NamedTuple):
|
|||
marks = (marks,)
|
||||
else:
|
||||
assert isinstance(marks, collections.abc.Collection)
|
||||
if any(i.name == "usefixtures" for i in marks):
|
||||
raise ValueError(
|
||||
"pytest.param cannot add pytest.mark.usefixtures; see "
|
||||
"https://docs.pytest.org/en/stable/reference/reference.html#pytest-param"
|
||||
)
|
||||
|
||||
if id is not None:
|
||||
if not isinstance(id, str):
|
||||
|
|
|
@ -407,6 +407,23 @@ class TestParameterize:
|
|||
res = pytester.runpytest("--collect-only")
|
||||
res.stdout.fnmatch_lines(["*spam-2*", "*ham-2*"])
|
||||
|
||||
def test_param_rejects_usefixtures(self, pytester: Pytester) -> None:
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
@pytest.mark.parametrize("x", [
|
||||
pytest.param(1, marks=[pytest.mark.usefixtures("foo")]),
|
||||
])
|
||||
def test_foo(x):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
res = pytester.runpytest("--collect-only")
|
||||
res.stdout.fnmatch_lines(
|
||||
["*test_param_rejects_usefixtures.py:4*", "*pytest.param(*"]
|
||||
)
|
||||
|
||||
|
||||
def test_function_instance(pytester: Pytester) -> None:
|
||||
items = pytester.getitems(
|
||||
|
|
Loading…
Reference in New Issue