Skip to content

Commit 25d8b5a

Browse files
committed
Add changelog, refactor code
1 parent e9310e5 commit 25d8b5a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

changelog/5712.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Now all arguments to ``@pytest.mark.parametrize`` need to be explicitly declared in the function signature or via ``indirect``.
2+
Previously it was possible to omit an argument if a fixture with the same name existed, which was just an accident of implementation and was not meant to be a part of the API.

src/_pytest/python.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ def parametrize(
928928
ids=None,
929929
scope=None,
930930
*,
931-
_param_mark: Optional[Mark] = None
931+
_param_mark: Optional[Mark] = None,
932932
):
933933
""" Add new invocations to the underlying test function using the list
934934
of argvalues for the given argnames. Parametrization is performed
@@ -998,10 +998,11 @@ def parametrize(
998998
scope = _find_parametrized_scope(argnames, self._arg2fixturedefs, indirect)
999999

10001000
self._validate_if_using_arg_names(argnames, indirect)
1001-
self._validate_explicit_parameters(argnames, indirect)
10021001

10031002
arg_values_types = self._resolve_arg_value_types(argnames, indirect)
10041003

1004+
self._validate_explicit_parameters(argnames, indirect)
1005+
10051006
# Use any already (possibly) generated ids with parametrize Marks.
10061007
if _param_mark and _param_mark._param_ids_from:
10071008
generated_ids = _param_mark._param_ids_from._param_ids_generated
@@ -1155,18 +1156,18 @@ def _validate_if_using_arg_names(self, argnames, indirect):
11551156
def _validate_explicit_parameters(self, argnames, indirect):
11561157
"""
11571158
The argnames in *parametrize* should either be declared explicitly via
1158-
indirect list or explicitly in the function
1159+
indirect list or in the function signature
11591160
11601161
:param List[str] argnames: list of argument names passed to ``parametrize()``.
11611162
:param indirect: same ``indirect`` parameter of ``parametrize()``.
11621163
:raise ValueError: if validation fails
11631164
"""
11641165
func_name = self.function.__name__
1165-
if type(indirect) is bool and indirect is True:
1166+
if isinstance(indirect, bool) and indirect is True:
11661167
return
11671168
parametrized_argnames = list()
11681169
funcargnames = _pytest.compat.getfuncargnames(self.function)
1169-
if type(indirect) is list:
1170+
if isinstance(indirect, Sequence):
11701171
for arg in argnames:
11711172
if arg not in indirect:
11721173
parametrized_argnames.append(arg)

0 commit comments

Comments
 (0)