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

Method warn

src/_pytest/nodes.py:274–309  ·  view source on GitHub ↗

Issue a warning for this Node. Warnings will be displayed after the test session, unless explicitly suppressed. :param Warning warning: The warning instance to issue. :raises ValueError: If ``warning`` instance is not a subclass of Warning. Example usa

(self, warning: Warning)

Source from the content-addressed store, hash-verified

272 return "<{} {}>".format(self.__class__.__name__, getattr(self, "name", None))
273
274 def warn(self, warning: Warning) -> None:
275 """Issue a warning for this Node.
276
277 Warnings will be displayed after the test session, unless explicitly suppressed.
278
279 :param Warning warning:
280 The warning instance to issue.
281
282 :raises ValueError: If ``warning`` instance is not a subclass of Warning.
283
284 Example usage:
285
286 .. code-block:: python
287
288 node.warn(PytestWarning("some message"))
289 node.warn(UserWarning("some message"))
290
291 .. versionchanged:: 6.2
292 Any subclass of :class:`Warning` is now accepted, rather than only
293 :class:`PytestWarning <pytest.PytestWarning>` subclasses.
294 """
295 # enforce type checks here to avoid getting a generic type error later otherwise.
296 if not isinstance(warning, Warning):
297 raise ValueError(
298 "warning must be an instance of Warning or subclass, got {!r}".format(
299 warning
300 )
301 )
302 path, lineno = get_fslocation_from_item(self)
303 assert lineno is not None
304 warnings.warn_explicit(
305 warning,
306 category=None,
307 filename=str(path),
308 lineno=lineno + 1,
309 )
310
311 # Methods for ordering nodes.
312

Callers 15

__init__Method · 0.45
record_xml_attributeFunction · 0.45
on_rm_rf_errorFunction · 0.45
_mock_aware_unwrapFunction · 0.45
async_warn_and_skipFunction · 0.45
gethookproxyMethod · 0.45

Calls 2

get_fslocation_from_itemFunction · 0.85
formatMethod · 0.45