MCPcopy Create free account
hub / github.com/pytest-dev/pytest / CallSpec2

Class CallSpec2

src/_pytest/python.py:927–994  ·  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

925@final
926@attr.s(frozen=True, slots=True, auto_attribs=True)
927class CallSpec2:
928 """A planned parameterized invocation of a test function.
929
930 Calculated during collection for a given test function's Metafunc.
931 Once collection is over, each callspec is turned into a single Item
932 and stored in item.callspec.
933 """
934
935 # arg name -> arg value which will be passed to the parametrized test
936 # function (direct parameterization).
937 funcargs: Dict[str, object] = attr.Factory(dict)
938 # arg name -> arg value which will be passed to a fixture of the same name
939 # (indirect parametrization).
940 params: Dict[str, object] = attr.Factory(dict)
941 # arg name -> arg index.
942 indices: Dict[str, int] = attr.Factory(dict)
943 # Used for sorting parametrized resources.
944 _arg2scope: Dict[str, Scope] = attr.Factory(dict)
945 # Parts which will be added to the item's name in `[..]` separated by "-".
946 _idlist: List[str] = attr.Factory(list)
947 # Marks which will be applied to the item.
948 marks: List[Mark] = attr.Factory(list)
949
950 def setmulti(
951 self,
952 *,
953 valtypes: Mapping[str, "Literal['params', 'funcargs']"],
954 argnames: Iterable[str],
955 valset: Iterable[object],
956 id: str,
957 marks: Iterable[Union[Mark, MarkDecorator]],
958 scope: Scope,
959 param_index: int,
960 ) -> "CallSpec2":
961 funcargs = self.funcargs.copy()
962 params = self.params.copy()
963 indices = self.indices.copy()
964 arg2scope = self._arg2scope.copy()
965 for arg, val in zip(argnames, valset):
966 if arg in params or arg in funcargs:
967 raise ValueError(f"duplicate {arg!r}")
968 valtype_for_arg = valtypes[arg]
969 if valtype_for_arg == "params":
970 params[arg] = val
971 elif valtype_for_arg == "funcargs":
972 funcargs[arg] = val
973 else:
974 assert_never(valtype_for_arg)
975 indices[arg] = param_index
976 arg2scope[arg] = scope
977 return CallSpec2(
978 funcargs=funcargs,
979 params=params,
980 arg2scope=arg2scope,
981 indices=indices,
982 idlist=[*self._idlist, id],
983 marks=[*self.marks, *normalize_mark_list(marks)],
984 )

Callers 2

setmultiMethod · 0.85
parametrizeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected