A pytest mark.
| 246 | @final |
| 247 | @dataclasses.dataclass(frozen=True) |
| 248 | class Mark: |
| 249 | """A pytest mark.""" |
| 250 | |
| 251 | #: Name of the mark. |
| 252 | name: str |
| 253 | #: Positional arguments of the mark decorator. |
| 254 | args: tuple[Any, ...] |
| 255 | #: Keyword arguments of the mark decorator. |
| 256 | kwargs: Mapping[str, Any] |
| 257 | |
| 258 | #: Source Mark for ids with parametrize Marks. |
| 259 | _param_ids_from: Mark | None = dataclasses.field(default=None, repr=False) |
| 260 | #: Resolved/generated ids with parametrize Marks. |
| 261 | _param_ids_generated: Sequence[str] | None = dataclasses.field( |
| 262 | default=None, repr=False |
| 263 | ) |
| 264 | |
| 265 | def __init__( |
| 266 | self, |
| 267 | name: str, |
| 268 | args: tuple[Any, ...], |
| 269 | kwargs: Mapping[str, Any], |
| 270 | param_ids_from: Mark | None = None, |
| 271 | param_ids_generated: Sequence[str] | None = None, |
| 272 | *, |
| 273 | _ispytest: bool = False, |
| 274 | ) -> None: |
| 275 | """:meta private:""" |
| 276 | check_ispytest(_ispytest) |
| 277 | # Weirdness to bypass frozen=True. |
| 278 | object.__setattr__(self, "name", name) |
| 279 | object.__setattr__(self, "args", args) |
| 280 | object.__setattr__(self, "kwargs", kwargs) |
| 281 | object.__setattr__(self, "_param_ids_from", param_ids_from) |
| 282 | object.__setattr__(self, "_param_ids_generated", param_ids_generated) |
| 283 | |
| 284 | def _has_param_ids(self) -> bool: |
| 285 | return "ids" in self.kwargs or len(self.args) >= 4 |
| 286 | |
| 287 | def combined_with(self, other: Mark) -> Mark: |
| 288 | """Return a new Mark which is a combination of this |
| 289 | Mark and another Mark. |
| 290 | |
| 291 | Combines by appending args and merging kwargs. |
| 292 | |
| 293 | :param Mark other: The mark to combine with. |
| 294 | :rtype: Mark |
| 295 | """ |
| 296 | assert self.name == other.name |
| 297 | |
| 298 | # Remember source of ids with parametrize Marks. |
| 299 | param_ids_from: Mark | None = None |
| 300 | if self.name == "parametrize": |
| 301 | if other._has_param_ids(): |
| 302 | param_ids_from = other |
| 303 | elif self._has_param_ids(): |
| 304 | param_ids_from = self |
| 305 |
no outgoing calls
no test coverage detected