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

Method __init__

src/_pytest/recwarn.py:232–259  ·  view source on GitHub ↗
(
        self,
        expected_warning: Optional[
            Union[Type[Warning], Tuple[Type[Warning], ...]]
        ] = Warning,
        match_expr: Optional[Union[str, Pattern[str]]] = None,
        *,
        _ispytest: bool = False,
    )

Source from the content-addressed store, hash-verified

230@final
231class WarningsChecker(WarningsRecorder):
232 def __init__(
233 self,
234 expected_warning: Optional[
235 Union[Type[Warning], Tuple[Type[Warning], ...]]
236 ] = Warning,
237 match_expr: Optional[Union[str, Pattern[str]]] = None,
238 *,
239 _ispytest: bool = False,
240 ) -> None:
241 check_ispytest(_ispytest)
242 super().__init__(_ispytest=True)
243
244 msg = "exceptions must be derived from Warning, not %s"
245 if expected_warning is None:
246 warnings.warn(WARNS_NONE_ARG, stacklevel=4)
247 expected_warning_tup = None
248 elif isinstance(expected_warning, tuple):
249 for exc in expected_warning:
250 if not issubclass(exc, Warning):
251 raise TypeError(msg % type(exc))
252 expected_warning_tup = expected_warning
253 elif issubclass(expected_warning, Warning):
254 expected_warning_tup = (expected_warning,)
255 else:
256 raise TypeError(msg % type(expected_warning))
257
258 self.expected_warning = expected_warning_tup
259 self.match_expr = match_expr
260
261 def __exit__(
262 self,

Callers 1

__init__Method · 0.45

Calls 2

check_ispytestFunction · 0.90
warnMethod · 0.45

Tested by

no test coverage detected