pytest-dev / pytest-dev/pytest

ParameterSet is private

Open
#13,431 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: parametrize topic: typing type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

When using pytest.param to create parameters for a test from a function, that function will return a list of ParameterSet but currently that is only available from _pytest.mark.structures which is private so importing it results in a private import warning.

It would be ideal if this structure was publicly available so developers don't need to disable warnings for uses of pytest.param when using fully hinted code.

The current situation looks like this, which requires a pyright ignore directive to be warning free.

This is simplified example, which could be defined inline but for more complex where the test cases were built by code using a function is more necessary.

from _pytest.mark.structures import ParameterSet  # pyright: ignore[reportPrivateImportUsage]
import pytest

def params() -> list[ParameterSet]:
    return [
        pytest.param("basic", 10, True, id="basic")
        pytest.param("advanced", 5, False, id="advanced")}
    ]


@pytest.mark.parametrize(("val1", "val2", "expected"), params())
async def test_ratelimiter(val1: str, val2: int, expected: bool) -> None:
       """Test code goes here..."""

Ideally this would be public to avoid this, for example:

from pytest.mark.structures import ParameterSet
import pytest

def params() -> list[ParameterSet]:
    return [
        pytest.param("basic", 10, True, id="basic")
        pytest.param("advanced", 5, False, id="advanced")}
    ]


@pytest.mark.parametrize(("val1", "val2", "expected"), params())
async def test_ratelimiter(val1: str, val2: int, expected: bool) -> None:
       """Test code goes here..."""

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at _pytest.mark.structures and trace the ParameterSet type used by pytest.param. Determine the intended public import path, then verify that type-hinted parameter factories can import it without a private-import warning and that the existing pytest parameterization behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.