Skip to content

Commit c0a03a2

Browse files
authored
Merge pull request #9712 from pytest-dev/backport-9710-to-7.0.x
[7.0.x] Revert "Deprecate raising unittest.SkipTest to skip tests during collection"
2 parents a8b9049 + bf8ef94 commit c0a03a2

File tree

8 files changed

+33
-43
lines changed

8 files changed

+33
-43
lines changed

changelog/8242.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The deprecation of raising :class:`unittest.SkipTest` to skip collection of
2+
tests during the pytest collection phase is reverted - this is now a supported
3+
feature again.

doc/en/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ Deprecations
211211
:class:`unittest.SkipTest` / :meth:`unittest.TestCase.skipTest` /
212212
:func:`unittest.skip` in unittest test cases is fully supported.
213213

214+
.. note:: This deprecation has been reverted in pytest 7.1.0.
215+
214216

215217
- `#8315 <https://github.com/pytest-dev/pytest/issues/8315>`_: Several behaviors of :meth:`Parser.addoption <pytest.Parser.addoption>` are now
216218
scheduled for removal in pytest 8 (deprecated since pytest 2.4.0):

doc/en/deprecations.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,6 @@ scheduled for removal in pytest 8 (deprecated since pytest 2.4.0):
241241
- ``parser.addoption(..., type="int/string/float/complex")`` - use ``type=int`` etc. instead.
242242

243243

244-
Raising ``unittest.SkipTest`` during collection
245-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246-
247-
.. deprecated:: 7.0
248-
249-
Raising :class:`unittest.SkipTest` to skip collection of tests during the
250-
pytest collection phase is deprecated. Use :func:`pytest.skip` instead.
251-
252-
Note: This deprecation only relates to using `unittest.SkipTest` during test
253-
collection. You are probably not doing that. Ordinary usage of
254-
:class:`unittest.SkipTest` / :meth:`unittest.TestCase.skipTest` /
255-
:func:`unittest.skip` in unittest test cases is fully supported.
256-
257244
Using ``pytest.warns(None)``
258245
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259246

src/_pytest/deprecated.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@
7474
# This deprecation is never really meant to be removed.
7575
PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.")
7676

77-
UNITTEST_SKIP_DURING_COLLECTION = PytestRemovedIn8Warning(
78-
"Raising unittest.SkipTest to skip tests during collection is deprecated. "
79-
"Use pytest.skip() instead."
80-
)
81-
8277
ARGUMENT_PERCENT_DEFAULT = PytestRemovedIn8Warning(
8378
'pytest now uses argparse. "%default" should be changed to "%(default)s"',
8479
)

src/_pytest/runner.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import bdb
33
import os
44
import sys
5-
import warnings
65
from typing import Callable
76
from typing import cast
87
from typing import Dict
@@ -28,7 +27,6 @@
2827
from _pytest.compat import final
2928
from _pytest.config.argparsing import Parser
3029
from _pytest.deprecated import check_ispytest
31-
from _pytest.deprecated import UNITTEST_SKIP_DURING_COLLECTION
3230
from _pytest.nodes import Collector
3331
from _pytest.nodes import Item
3432
from _pytest.nodes import Node
@@ -379,11 +377,6 @@ def pytest_make_collect_report(collector: Collector) -> CollectReport:
379377
# Type ignored because unittest is loaded dynamically.
380378
skip_exceptions.append(unittest.SkipTest) # type: ignore
381379
if isinstance(call.excinfo.value, tuple(skip_exceptions)):
382-
if unittest is not None and isinstance(
383-
call.excinfo.value, unittest.SkipTest # type: ignore[attr-defined]
384-
):
385-
warnings.warn(UNITTEST_SKIP_DURING_COLLECTION, stacklevel=2)
386-
387380
outcome = "skipped"
388381
r_ = collector._repr_failure_py(call.excinfo, "line")
389382
assert isinstance(r_, ExceptionChainRepr), repr(r_)

testing/deprecated_test.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,6 @@ def __init__(self, foo: int, *, _ispytest: bool = False) -> None:
142142
PrivateInit(10, _ispytest=True)
143143

144144

145-
def test_raising_unittest_skiptest_during_collection_is_deprecated(
146-
pytester: Pytester,
147-
) -> None:
148-
pytester.makepyfile(
149-
"""
150-
import unittest
151-
raise unittest.SkipTest()
152-
"""
153-
)
154-
result = pytester.runpytest()
155-
result.stdout.fnmatch_lines(
156-
[
157-
"*PytestRemovedIn8Warning: Raising unittest.SkipTest*",
158-
]
159-
)
160-
161-
162145
@pytest.mark.parametrize("hooktype", ["hook", "ihook"])
163146
def test_hookproxy_warnings_for_pathlib(tmp_path, hooktype, request):
164147
path = legacy_path(tmp_path)

testing/test_nose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def test_failing():
345345
"""
346346
)
347347
result = pytester.runpytest(p)
348-
result.assert_outcomes(skipped=1, warnings=1)
348+
result.assert_outcomes(skipped=1, warnings=0)
349349

350350

351351
def test_SkipTest_in_test(pytester: Pytester) -> None:

testing/test_unittest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,3 +1498,30 @@ def test_it(self):
14981498
assert passed == 1
14991499
assert failed == 1
15001500
assert reprec.ret == 1
1501+
1502+
1503+
def test_raising_unittest_skiptest_during_collection(
1504+
pytester: Pytester,
1505+
) -> None:
1506+
pytester.makepyfile(
1507+
"""
1508+
import unittest
1509+
1510+
class TestIt(unittest.TestCase):
1511+
def test_it(self): pass
1512+
def test_it2(self): pass
1513+
1514+
raise unittest.SkipTest()
1515+
1516+
class TestIt2(unittest.TestCase):
1517+
def test_it(self): pass
1518+
def test_it2(self): pass
1519+
"""
1520+
)
1521+
reprec = pytester.inline_run()
1522+
passed, skipped, failed = reprec.countoutcomes()
1523+
assert passed == 0
1524+
# Unittest reports one fake test for a skipped module.
1525+
assert skipped == 1
1526+
assert failed == 0
1527+
assert reprec.ret == ExitCode.NO_TESTS_COLLECTED

0 commit comments

Comments
 (0)