Skip to content

Commit 79fbf93

Browse files
authored
Merge pull request #14612 from pytest-dev/patchback/backports/9.1.x/974ed48b696d706b7e7cc834ddca9bb0edd488a4/pr-14611
[PR #14611/974ed48b backport][9.1.x] mark/structures: undo non-collection-argvalues type-check time deprecation due to mypy bug
2 parents b6b9a79 + 0d312eb commit 79fbf93

3 files changed

Lines changed: 12 additions & 28 deletions

File tree

changelog/14606.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed ``list-item`` typing errors from mypy in :ref:`@pytest.mark.parametrize <pytest.mark.parametrize ref>` ``argvalues`` parameter.

src/_pytest/mark/structures.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import warnings
2222

2323
from .._code import getfslineno
24-
from ..compat import deprecated
2524
from ..compat import NOTSET
2625
from ..compat import NotSetType
2726
from _pytest.config import Config
@@ -537,31 +536,16 @@ def __call__(
537536
) -> MarkDecorator: ...
538537

539538
class _ParametrizeMarkDecorator(MarkDecorator):
540-
@overload # type: ignore[override,no-overload-impl]
541-
def __call__(
542-
self,
543-
argnames: str | Sequence[str],
544-
argvalues: Collection[ParameterSet | Sequence[object] | object],
545-
*,
546-
indirect: bool | Sequence[str] = ...,
547-
ids: Iterable[None | str | float | int | bool | _HiddenParam]
548-
| Callable[[Any], object | None]
549-
| None = ...,
550-
scope: ScopeName | None = ...,
551-
) -> MarkDecorator: ...
552-
553-
@overload
554-
@deprecated(
555-
"Passing a non-Collection iterable to the 'argvalues' parameter of @pytest.mark.parametrize is deprecated. "
556-
"Convert argvalues to a list or tuple.",
557-
)
558-
def __call__(
539+
def __call__( # type: ignore[override]
559540
self,
560541
argnames: str | Sequence[str],
561542
argvalues: Iterable[ParameterSet | Sequence[object] | object],
543+
# TODO(pytest10): Change to below after PARAMETRIZE_NON_COLLECTION_ITERABLE deprecation.
544+
# Overload doesn't work, see #14606.
545+
# argvalues: Collection[ParameterSet | Sequence[object] | object],
562546
*,
563547
indirect: bool | Sequence[str] = ...,
564-
ids: Iterable[None | str | float | int | bool]
548+
ids: Iterable[None | str | float | int | bool | _HiddenParam]
565549
| Callable[[Any], object | None]
566550
| None = ...,
567551
scope: ScopeName | None = ...,

testing/typing_checks.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ def test_hidden_param(x: int) -> None:
6767
pass
6868

6969

70-
# Test @pytest.mark.parametrize iterator argvalues deprecation.
71-
# Will be complain about unused type ignore if doesn't work.
72-
@pytest.mark.parametrize("x", iter(range(10))) # type: ignore[deprecated]
73-
def test_it(x: int) -> None:
74-
pass
75-
76-
7770
# Issue #14137.
7871
def check_scope_typing() -> None:
7972

8073
custom_scope: ScopeName = "function"
8174
assert_type(custom_scope, ScopeName)
75+
76+
77+
# Issue #14606.
78+
@pytest.mark.parametrize("x", [ImportError, AttributeError])
79+
def check_mypy_bug_with_argvalues(x) -> None:
80+
pass

0 commit comments

Comments
 (0)