Skip to content

Commit b6eaf31

Browse files
authored
Merge pull request #10219 from bluetech/parametrize-argnames-type
mark: allow any Sequence[str] for parametrize(argnames), not just list/tuple
2 parents 2e7c718 + 67e29d2 commit b6eaf31

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

changelog/10218.improvement.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``@pytest.mark.parametrize()`` (and similar functions) now accepts any ``Sequence[str]`` for the argument names,
2+
instead of just ``list[str]`` and ``tuple[str, ...]``.
3+
4+
(Note that ``str``, which is itself a ``Sequence[str]``, is still treated as a
5+
comma-delimited name list, as before).

src/_pytest/mark/structures.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ def extract_from(
126126

127127
@staticmethod
128128
def _parse_parametrize_args(
129-
argnames: Union[str, List[str], Tuple[str, ...]],
129+
argnames: Union[str, Sequence[str]],
130130
argvalues: Iterable[Union["ParameterSet", Sequence[object], object]],
131131
*args,
132132
**kwargs,
133-
) -> Tuple[Union[List[str], Tuple[str, ...]], bool]:
134-
if not isinstance(argnames, (tuple, list)):
133+
) -> Tuple[Sequence[str], bool]:
134+
if isinstance(argnames, str):
135135
argnames = [x.strip() for x in argnames.split(",") if x.strip()]
136136
force_tuple = len(argnames) == 1
137137
else:
@@ -150,12 +150,12 @@ def _parse_parametrize_parameters(
150150
@classmethod
151151
def _for_parametrize(
152152
cls,
153-
argnames: Union[str, List[str], Tuple[str, ...]],
153+
argnames: Union[str, Sequence[str]],
154154
argvalues: Iterable[Union["ParameterSet", Sequence[object], object]],
155155
func,
156156
config: Config,
157157
nodeid: str,
158-
) -> Tuple[Union[List[str], Tuple[str, ...]], List["ParameterSet"]]:
158+
) -> Tuple[Sequence[str], List["ParameterSet"]]:
159159
argnames, force_tuple = cls._parse_parametrize_args(argnames, argvalues)
160160
parameters = cls._parse_parametrize_parameters(argvalues, force_tuple)
161161
del argvalues
@@ -434,7 +434,7 @@ def __call__(
434434
class _ParametrizeMarkDecorator(MarkDecorator):
435435
def __call__( # type: ignore[override]
436436
self,
437-
argnames: Union[str, List[str], Tuple[str, ...]],
437+
argnames: Union[str, Sequence[str]],
438438
argvalues: Iterable[Union[ParameterSet, Sequence[object], object]],
439439
*,
440440
indirect: Union[bool, Sequence[str]] = ...,

src/_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ def __init__(
12071207

12081208
def parametrize(
12091209
self,
1210-
argnames: Union[str, List[str], Tuple[str, ...]],
1210+
argnames: Union[str, Sequence[str]],
12111211
argvalues: Iterable[Union[ParameterSet, Sequence[object], object]],
12121212
indirect: Union[bool, Sequence[str]] = False,
12131213
ids: Optional[

0 commit comments

Comments
 (0)