summaryrefslogtreecommitdiff
path: root/src/_pytest/nodes.py
diff options
context:
space:
mode:
authorSimon K <jackofspaces@gmail.com>2020-11-21 13:49:17 +0000
committerGitHub <noreply@github.com>2020-11-21 10:49:17 -0300
commit52fef811c252fa65b555c8af7b857d7d064e46da (patch)
treed1e8324f209e208c392c441dafcc644e4305172c /src/_pytest/nodes.py
parentafd53ede6f3c950df3bfc9e81afdd45e09ef6d2b (diff)
downloadpytest-52fef811c252fa65b555c8af7b857d7d064e46da.tar.gz
permit node to warn with any warning type, not just PytestWarning (#8052)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Diffstat (limited to 'src/_pytest/nodes.py')
-rw-r--r--src/_pytest/nodes.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py
index dd58d5df9..27434fb6a 100644
--- a/src/_pytest/nodes.py
+++ b/src/_pytest/nodes.py
@@ -34,7 +34,6 @@ from _pytest.store import Store
if TYPE_CHECKING:
# Imported here due to circular import.
from _pytest.main import Session
- from _pytest.warning_types import PytestWarning
from _pytest._code.code import _TracebackStyle
@@ -198,27 +197,31 @@ class Node(metaclass=NodeMeta):
def __repr__(self) -> str:
return "<{} {}>".format(self.__class__.__name__, getattr(self, "name", None))
- def warn(self, warning: "PytestWarning") -> None:
+ def warn(self, warning: Warning) -> None:
"""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. Must be a subclass of PytestWarning.
+ The warning instance to issue.
- :raises ValueError: If ``warning`` instance is not a subclass of PytestWarning.
+ :raises ValueError: If ``warning`` instance is not a subclass of Warning.
Example usage:
.. code-block:: python
node.warn(PytestWarning("some message"))
- """
- from _pytest.warning_types import PytestWarning
+ node.warn(UserWarning("some message"))
- if not isinstance(warning, PytestWarning):
+ .. versionchanged:: 6.2
+ Any subclass of :class:`Warning` is now accepted, rather than only
+ :class:`PytestWarning <pytest.PytestWarning>` subclasses.
+ """
+ # enforce type checks here to avoid getting a generic type error later otherwise.
+ if not isinstance(warning, Warning):
raise ValueError(
- "warning must be an instance of PytestWarning or subclass, got {!r}".format(
+ "warning must be an instance of Warning or subclass, got {!r}".format(
warning
)
)