Merge pull request #10219 from bluetech/parametrize-argnames-type

mark: allow any Sequence[str] for parametrize(argnames), not just list/tuple
This commit is contained in:
Ran Benita 2022-08-15 19:59:45 +03:00 committed by GitHub
commit b6eaf319d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View File

@ -0,0 +1,5 @@
``@pytest.mark.parametrize()`` (and similar functions) now accepts any ``Sequence[str]`` for the argument names,
instead of just ``list[str]`` and ``tuple[str, ...]``.
(Note that ``str``, which is itself a ``Sequence[str]``, is still treated as a
comma-delimited name list, as before).

View File

@ -126,12 +126,12 @@ class ParameterSet(NamedTuple):
@staticmethod
def _parse_parametrize_args(
argnames: Union[str, List[str], Tuple[str, ...]],
argnames: Union[str, Sequence[str]],
argvalues: Iterable[Union["ParameterSet", Sequence[object], object]],
*args,
**kwargs,
) -> Tuple[Union[List[str], Tuple[str, ...]], bool]:
if not isinstance(argnames, (tuple, list)):
) -> Tuple[Sequence[str], bool]:
if isinstance(argnames, str):
argnames = [x.strip() for x in argnames.split(",") if x.strip()]
force_tuple = len(argnames) == 1
else:
@ -150,12 +150,12 @@ class ParameterSet(NamedTuple):
@classmethod
def _for_parametrize(
cls,
argnames: Union[str, List[str], Tuple[str, ...]],
argnames: Union[str, Sequence[str]],
argvalues: Iterable[Union["ParameterSet", Sequence[object], object]],
func,
config: Config,
nodeid: str,
) -> Tuple[Union[List[str], Tuple[str, ...]], List["ParameterSet"]]:
) -> Tuple[Sequence[str], List["ParameterSet"]]:
argnames, force_tuple = cls._parse_parametrize_args(argnames, argvalues)
parameters = cls._parse_parametrize_parameters(argvalues, force_tuple)
del argvalues
@ -434,7 +434,7 @@ if TYPE_CHECKING:
class _ParametrizeMarkDecorator(MarkDecorator):
def __call__( # type: ignore[override]
self,
argnames: Union[str, List[str], Tuple[str, ...]],
argnames: Union[str, Sequence[str]],
argvalues: Iterable[Union[ParameterSet, Sequence[object], object]],
*,
indirect: Union[bool, Sequence[str]] = ...,

View File

@ -1207,7 +1207,7 @@ class Metafunc:
def parametrize(
self,
argnames: Union[str, List[str], Tuple[str, ...]],
argnames: Union[str, Sequence[str]],
argvalues: Iterable[Union[ParameterSet, Sequence[object], object]],
indirect: Union[bool, Sequence[str]] = False,
ids: Optional[