Repository navigation
feat(mark): expose pytest.ParameterSet in public API (#13431)
#15193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9ae02e6
49fd4ff
e065b43
268e28e
ff1b6f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Exposed :class:`pytest.ParameterSet` as the type of the return value of :func:`pytest.param()`. | ||
| This can be used in type annotations and ``isinstance`` checks. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -81,33 +81,37 @@ def get_empty_parameterset_mark( | |||||||
|
|
||||||||
|
|
||||||||
| class ParameterSet(NamedTuple): | ||||||||
| """A set of values for a set of parameters along with associated marks and | ||||||||
| an optional ID for the set. | ||||||||
|
|
||||||||
| Examples:: | ||||||||
|
|
||||||||
| pytest.param(1, 2, 3) | ||||||||
| # ParameterSet(values=(1, 2, 3), marks=(), id=None) | ||||||||
| """The return type of :func:`pytest.param`. | ||||||||
|
|
||||||||
| pytest.param("hello", id="greeting") | ||||||||
| # ParameterSet(values=("hello",), marks=(), id="greeting") | ||||||||
|
|
||||||||
| # Parameter set with marks | ||||||||
| pytest.param(42, marks=pytest.mark.xfail) | ||||||||
| # ParameterSet(values=(42,), marks=(MarkDecorator(...),), id=None) | ||||||||
| A set of values for a set of parameters along with associated marks and | ||||||||
| an optional ID for the set. | ||||||||
|
|
||||||||
| # From parametrize mark (parameter names + list of parameter sets) | ||||||||
| pytest.mark.parametrize( | ||||||||
| ("a", "b", "expected"), | ||||||||
| [ | ||||||||
| (1, 2, 3), | ||||||||
| pytest.param(40, 2, 42, id="everything"), | ||||||||
| ], | ||||||||
| ) | ||||||||
| # ParameterSet(values=(1, 2, 3), marks=(), id=None) | ||||||||
| # ParameterSet(values=(40, 2, 42), marks=(), id="everything") | ||||||||
| .. versionadded:: 9.2 | ||||||||
| """ | ||||||||
|
|
||||||||
| # Examples: | ||||||||
| # | ||||||||
| # pytest.param(1, 2, 3) | ||||||||
| # # ParameterSet(values=(1, 2, 3), marks=(), id=None) | ||||||||
| # | ||||||||
| # pytest.param("hello", id="greeting") | ||||||||
| # # ParameterSet(values=("hello",), marks=(), id="greeting") | ||||||||
| # | ||||||||
| # # Parameter set with marks | ||||||||
| # pytest.param(42, marks=pytest.mark.xfail) | ||||||||
| # # ParameterSet(values=(42,), marks=(MarkDecorator(...),), id=None) | ||||||||
| # | ||||||||
| # # From parametrize mark (parameter names + list of parameter sets) | ||||||||
| # pytest.mark.parametrize( | ||||||||
| # ("a", "b", "expected"), | ||||||||
| # [ | ||||||||
| # (1, 2, 3), | ||||||||
| # pytest.param(40, 2, 42, id="everything"), | ||||||||
| # ], | ||||||||
| # ) | ||||||||
| # # ParameterSet(values=(1, 2, 3), marks=(), id=None) | ||||||||
| # # ParameterSet(values=(40, 2, 42), marks=(), id="everything") | ||||||||
|
|
||||||||
| values: Sequence[object | NotSetType] | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What @RonnyPfannschmidt said about |
||||||||
| marks: Collection[MarkDecorator | Mark] | ||||||||
| id: str | _HiddenParam | None | ||||||||
|
|
@@ -119,6 +123,7 @@ def param( | |||||||
| marks: MarkDecorator | Collection[MarkDecorator | Mark] = (), | ||||||||
| id: str | _HiddenParam | None = None, | ||||||||
| ) -> ParameterSet: | ||||||||
| """:meta private:""" | ||||||||
| if isinstance(marks, MarkDecorator): | ||||||||
| marks = (marks,) | ||||||||
| else: | ||||||||
|
|
@@ -145,6 +150,8 @@ def extract_from( | |||||||
| ) -> ParameterSet: | ||||||||
| """Extract from an object or objects. | ||||||||
|
|
||||||||
| :meta private: | ||||||||
|
|
||||||||
| :param parameterset: | ||||||||
| A legacy style parameterset that may or may not be a tuple, | ||||||||
| and may or may not be wrapped into a mess of mark objects. | ||||||||
|
|
@@ -259,6 +266,10 @@ def _for_parametrize( | |||||||
| return argnames, parameters | ||||||||
|
|
||||||||
|
|
||||||||
| # mypy doesn't like `__module__` defined inline in the NamedTuple. | ||||||||
| ParameterSet.__module__ = "pytest" | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose a clarifying comment would be nice:
Suggested change
|
||||||||
|
|
||||||||
|
|
||||||||
| @final | ||||||||
| @dataclasses.dataclass(frozen=True) | ||||||||
| class Mark: | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When defined like this the documentation doesn't show that this is a namedtuple. But that's fine for now, not sure we really want to promise this officially.