Deprecate raising unittest.SkipTest to skip tests during collection
It is not very clear why this code exists -- we are not running any unittest or nose code during collection, and really these frameworks don't have the concept of collection at all, and just raising these exceptions at e.g. the module level would cause an error. So unless I'm missing something, I don't think anyone is using this. Deprecate it so we can eventually clear up this code and keep unittest more tightly restricted to its plugin.
This commit is contained in:
@@ -64,6 +64,11 @@ STRICT_OPTION = PytestDeprecationWarning(
|
||||
|
||||
PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.")
|
||||
|
||||
UNITTEST_SKIP_DURING_COLLECTION = PytestDeprecationWarning(
|
||||
"Raising unittest.SkipTest to skip tests during collection is deprecated. "
|
||||
"Use pytest.skip() instead."
|
||||
)
|
||||
|
||||
|
||||
# You want to make some `__init__` or function "private".
|
||||
#
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import bdb
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
from typing import Callable
|
||||
from typing import cast
|
||||
from typing import Dict
|
||||
@@ -27,6 +28,7 @@ from _pytest._code.code import TerminalRepr
|
||||
from _pytest.compat import final
|
||||
from _pytest.config.argparsing import Parser
|
||||
from _pytest.deprecated import check_ispytest
|
||||
from _pytest.deprecated import UNITTEST_SKIP_DURING_COLLECTION
|
||||
from _pytest.nodes import Collector
|
||||
from _pytest.nodes import Item
|
||||
from _pytest.nodes import Node
|
||||
@@ -374,6 +376,11 @@ def pytest_make_collect_report(collector: Collector) -> CollectReport:
|
||||
# Type ignored because unittest is loaded dynamically.
|
||||
skip_exceptions.append(unittest.SkipTest) # type: ignore
|
||||
if isinstance(call.excinfo.value, tuple(skip_exceptions)):
|
||||
if unittest is not None and isinstance(
|
||||
call.excinfo.value, unittest.SkipTest # type: ignore[attr-defined]
|
||||
):
|
||||
warnings.warn(UNITTEST_SKIP_DURING_COLLECTION, stacklevel=2)
|
||||
|
||||
outcome = "skipped"
|
||||
r_ = collector._repr_failure_py(call.excinfo, "line")
|
||||
assert isinstance(r_, ExceptionChainRepr), repr(r_)
|
||||
|
||||
Reference in New Issue
Block a user