Skip to content

Commit

Permalink
Revert "Deprecate raising unittest.SkipTest to skip tests during coll…
Browse files Browse the repository at this point in the history
…ection"

This reverts commit 25e657b.

Turns out that this *is* a working unittest feature, which pytest should
support, so undo the deprecation.
  • Loading branch information
bluetech committed Feb 23, 2022
1 parent 0c80a1c commit df9929d
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 43 deletions.
3 changes: 3 additions & 0 deletions changelog/8242.bugfix.rst
@@ -0,0 +1,3 @@
The deprecation of raising :class:`unittest.SkipTest` to skip collection of
tests during the pytest collection phase is reverted - this is now a supported
feature again.
2 changes: 2 additions & 0 deletions doc/en/changelog.rst
Expand Up @@ -211,6 +211,8 @@ Deprecations
:class:`unittest.SkipTest` / :meth:`unittest.TestCase.skipTest` /
:func:`unittest.skip` in unittest test cases is fully supported.

NOTE: This deprecation has been reverted in pytest 7.1.0.


- `#8315 <https://github.com/pytest-dev/pytest/issues/8315>`_: Several behaviors of :meth:`Parser.addoption <pytest.Parser.addoption>` are now
scheduled for removal in pytest 8 (deprecated since pytest 2.4.0):
Expand Down
13 changes: 0 additions & 13 deletions doc/en/deprecations.rst
Expand Up @@ -241,19 +241,6 @@ scheduled for removal in pytest 8 (deprecated since pytest 2.4.0):
- ``parser.addoption(..., type="int/string/float/complex")`` - use ``type=int`` etc. instead.


Raising ``unittest.SkipTest`` during collection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 7.0

Raising :class:`unittest.SkipTest` to skip collection of tests during the
pytest collection phase is deprecated. Use :func:`pytest.skip` instead.

Note: This deprecation only relates to using `unittest.SkipTest` during test
collection. You are probably not doing that. Ordinary usage of
:class:`unittest.SkipTest` / :meth:`unittest.TestCase.skipTest` /
:func:`unittest.skip` in unittest test cases is fully supported.

Using ``pytest.warns(None)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
5 changes: 0 additions & 5 deletions src/_pytest/deprecated.py
Expand Up @@ -47,11 +47,6 @@
# This deprecation is never really meant to be removed.
PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.")

UNITTEST_SKIP_DURING_COLLECTION = PytestRemovedIn8Warning(
"Raising unittest.SkipTest to skip tests during collection is deprecated. "
"Use pytest.skip() instead."
)

ARGUMENT_PERCENT_DEFAULT = PytestRemovedIn8Warning(
'pytest now uses argparse. "%default" should be changed to "%(default)s"',
)
Expand Down
7 changes: 0 additions & 7 deletions src/_pytest/runner.py
Expand Up @@ -2,7 +2,6 @@
import bdb
import os
import sys
import warnings
from typing import Callable
from typing import cast
from typing import Dict
Expand All @@ -28,7 +27,6 @@
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
Expand Down Expand Up @@ -379,11 +377,6 @@ 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_)
Expand Down
17 changes: 0 additions & 17 deletions testing/deprecated_test.py
Expand Up @@ -86,23 +86,6 @@ def __init__(self, foo: int, *, _ispytest: bool = False) -> None:
PrivateInit(10, _ispytest=True)


def test_raising_unittest_skiptest_during_collection_is_deprecated(
pytester: Pytester,
) -> None:
pytester.makepyfile(
"""
import unittest
raise unittest.SkipTest()
"""
)
result = pytester.runpytest()
result.stdout.fnmatch_lines(
[
"*PytestRemovedIn8Warning: Raising unittest.SkipTest*",
]
)


@pytest.mark.parametrize("hooktype", ["hook", "ihook"])
def test_hookproxy_warnings_for_pathlib(tmp_path, hooktype, request):
path = legacy_path(tmp_path)
Expand Down
2 changes: 1 addition & 1 deletion testing/test_nose.py
Expand Up @@ -345,7 +345,7 @@ def test_failing():
"""
)
result = pytester.runpytest(p)
result.assert_outcomes(skipped=1, warnings=1)
result.assert_outcomes(skipped=1, warnings=0)


def test_SkipTest_in_test(pytester: Pytester) -> None:
Expand Down
27 changes: 27 additions & 0 deletions testing/test_unittest.py
Expand Up @@ -1498,3 +1498,30 @@ def test_it(self):
assert passed == 1
assert failed == 1
assert reprec.ret == 1


def test_raising_unittest_skiptest_during_collection(
pytester: Pytester,
) -> None:
pytester.makepyfile(
"""
import unittest
class TestIt(unittest.TestCase):
def test_it(self): pass
def test_it2(self): pass
raise unittest.SkipTest()
class TestIt2(unittest.TestCase):
def test_it(self): pass
def test_it2(self): pass
"""
)
reprec = pytester.inline_run()
passed, skipped, failed = reprec.countoutcomes()
assert passed == 0
# Unittest reports one fake test for a skipped module.
assert skipped == 1
assert failed == 0
assert reprec.ret == ExitCode.NO_TESTS_COLLECTED

0 comments on commit df9929d

Please sign in to comment.