MCPcopy
hub / github.com/pytest-dev/pytest / ParameterSet

Class ParameterSet

src/_pytest/mark/structures.py:80–243  ·  view source on GitHub ↗

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) pytest.param("hello", id="greeting") # ParameterSet(values=("hello",), m

Source from the content-addressed store, hash-verified

78
79
80class ParameterSet(NamedTuple):
81 """A set of values for a set of parameters along with associated marks and
82 an optional ID for the set.
83
84 Examples::
85
86 pytest.param(1, 2, 3)
87 # ParameterSet(values=(1, 2, 3), marks=(), id=None)
88
89 pytest.param("hello", id="greeting")
90 # ParameterSet(values=("hello",), marks=(), id="greeting")
91
92 # Parameter set with marks
93 pytest.param(42, marks=pytest.mark.xfail)
94 # ParameterSet(values=(42,), marks=(MarkDecorator(...),), id=None)
95
96 # From parametrize mark (parameter names + list of parameter sets)
97 pytest.mark.parametrize(
98 ("a", "b", "expected"),
99 [
100 (1, 2, 3),
101 pytest.param(40, 2, 42, id="everything"),
102 ],
103 )
104 # ParameterSet(values=(1, 2, 3), marks=(), id=None)
105 # ParameterSet(values=(40, 2, 42), marks=(), id="everything")
106 """
107
108 values: Sequence[object | NotSetType]
109 marks: Collection[MarkDecorator | Mark]
110 id: str | _HiddenParam | None
111
112 @classmethod
113 def param(
114 cls,
115 *values: object,
116 marks: MarkDecorator | Collection[MarkDecorator | Mark] = (),
117 id: str | _HiddenParam | None = None,
118 ) -> ParameterSet:
119 if isinstance(marks, MarkDecorator):
120 marks = (marks,)
121 else:
122 assert isinstance(marks, collections.abc.Collection)
123 if any(i.name == "usefixtures" for i in marks):
124 raise ValueError(
125 "pytest.param cannot add pytest.mark.usefixtures; see "
126 "https://docs.pytest.org/en/stable/reference/reference.html#pytest-param"
127 )
128
129 if id is not None:
130 if not isinstance(id, str) and id is not HIDDEN_PARAM:
131 raise TypeError(
132 "Expected id to be a string or a `pytest.HIDDEN_PARAM` sentinel, "
133 f"got {type(id)}: {id!r}",
134 )
135 return cls(values, marks, id)
136
137 @classmethod

Callers 1

_for_parametrizeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected