diff --git a/changelog/14234.improvement.rst b/changelog/14234.improvement.rst new file mode 100644 index 00000000000..9d102256969 --- /dev/null +++ b/changelog/14234.improvement.rst @@ -0,0 +1 @@ +Allow ``pytest.HIDDEN_PARAM`` in ``parametrize(ids=...)`` type annotations. diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 0fa6e8babba..f70a655ce72 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -532,7 +532,7 @@ def __call__( argvalues: Collection[ParameterSet | Sequence[object] | object], *, indirect: bool | Sequence[str] = ..., - ids: Iterable[None | str | float | int | bool] + ids: Iterable[None | str | float | int | bool | _HiddenParam] | Callable[[Any], object | None] | None = ..., scope: _ScopeName | None = ..., diff --git a/testing/typing_checks.py b/testing/typing_checks.py index ff1c0e60cd9..942243420a9 100644 --- a/testing/typing_checks.py +++ b/testing/typing_checks.py @@ -60,6 +60,12 @@ def check_testreport_attributes(report: TestReport) -> None: assert_type(report.location, tuple[str, int | None, str]) +# Issue #14234. +@pytest.mark.parametrize("x", [1, 2], ids=[pytest.HIDDEN_PARAM, "visible"]) +def test_hidden_param(x: int) -> None: + pass + + # Test @pytest.mark.parametrize iterator argvalues deprecation. # Will be complain about unused type ignore if doesn't work. @pytest.mark.parametrize("x", iter(range(10))) # type: ignore[deprecated]