Skip to content

Type annotation for parametrize ids should allow HIDDEN_PARAM #14234

@jonathan-conder

Description

@jonathan-conder

Current the ids keyword argument of pytest.mark.parametrize is an Iterable[None | str | float | int | bool]. It should also allow pytest.HIDDEN_PARAM (similar to pytest.param(id=...)).

$ pip list
Package           Version                 Editable project location
----------------- ----------------------- -------------------------
iniconfig         2.3.0
librt             0.8.1
mypy              1.19.1
mypy_extensions   1.1.0
packaging         26.0
pathspec          1.0.4
pip               24.0
pluggy            1.6.0
Pygments          2.19.2
pytest            9.1.0.dev216+g9fd1eebd8 /home/user/pytest
typing_extensions 4.15.0

$ pytest --version
pytest 9.1.0.dev216+g9fd1eebd8

$ cat example.py
from __future__ import annotations

import pytest


@pytest.mark.parametrize("a", [1], ids=[pytest.HIDDEN_PARAM])
def test_a(a: int) -> None:
    assert a == 1

$ mypy example.py 
example.py:6: error: List item 0 has incompatible type "_HiddenParam"; expected "str | float | int | None"  [list-item]
Found 1 error in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions