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

Class CallSpec2

src/_pytest/python.py:1093–1151  ·  view source on GitHub ↗

A planned parameterized invocation of a test function. Calculated during collection for a given test function's Metafunc. Once collection is over, each callspec is turned into a single Item and stored in item.callspec.

Source from the content-addressed store, hash-verified

1091@final
1092@dataclasses.dataclass(frozen=True)
1093class CallSpec2:
1094 """A planned parameterized invocation of a test function.
1095
1096 Calculated during collection for a given test function's Metafunc.
1097 Once collection is over, each callspec is turned into a single Item
1098 and stored in item.callspec.
1099 """
1100
1101 # arg name -> arg value which will be passed to a fixture of the same name.
1102 params: dict[str, object] = dataclasses.field(default_factory=dict)
1103 # arg name -> arg index.
1104 indices: dict[str, int] = dataclasses.field(default_factory=dict)
1105 # arg name -> parameter scope.
1106 # Used for sorting parametrized resources.
1107 _arg2scope: Mapping[str, Scope] = dataclasses.field(default_factory=dict)
1108 # Parts which will be added to the item's name in `[..]` separated by "-".
1109 _idlist: Sequence[str] = dataclasses.field(default_factory=tuple)
1110 # Marks which will be applied to the item.
1111 marks: list[Mark] = dataclasses.field(default_factory=list)
1112
1113 def setmulti(
1114 self,
1115 *,
1116 argnames: Iterable[str],
1117 valset: Iterable[object],
1118 id: str | _HiddenParam,
1119 marks: Iterable[Mark | MarkDecorator],
1120 scope: Scope,
1121 param_index: int,
1122 nodeid: str,
1123 ) -> CallSpec2:
1124 params = self.params.copy()
1125 indices = self.indices.copy()
1126 arg2scope = dict(self._arg2scope)
1127 for arg, val in zip(argnames, valset, strict=True):
1128 if arg in params:
1129 raise nodes.Collector.CollectError(
1130 f"{nodeid}: duplicate parametrization of {arg!r}"
1131 )
1132 params[arg] = val
1133 indices[arg] = param_index
1134 arg2scope[arg] = scope
1135 return CallSpec2(
1136 params=params,
1137 indices=indices,
1138 _arg2scope=arg2scope,
1139 _idlist=self._idlist if id is HIDDEN_PARAM else [*self._idlist, id],
1140 marks=[*self.marks, *normalize_mark_list(marks)],
1141 )
1142
1143 def getparam(self, name: str) -> object:
1144 try:
1145 return self.params[name]
1146 except KeyError as e:
1147 raise ValueError(name) from e
1148
1149 @property
1150 def id(self) -> str:

Callers 2

setmultiMethod · 0.85
parametrizeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected