Skip to content

Commit 4868d0d

Browse files
authored
Drop unittest2 support (#5565)
Drop unittest2 support
2 parents 666acc9 + 24a66db commit 4868d0d

File tree

6 files changed

+28
-33
lines changed

6 files changed

+28
-33
lines changed

changelog/5565.removal.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Removed unused support code for `unittest2 <https://pypi.org/project/unittest2/>`__.
2+
3+
The ``unittest2`` backport module is no longer
4+
necessary since Python 3.3+, and the small amount of code in pytest to support it also doesn't seem
5+
to be used: after removed, all tests still pass unchanged.
6+
7+
Although our policy is to introduce a deprecation period before removing any features or support
8+
for third party libraries, because this code is apparently not used
9+
at all (even if ``unittest2`` is used by a test suite executed by pytest), it was decided to
10+
remove it in this release.
11+
12+
If you experience a regression because of this, please
13+
`file an issue <https://github.com/pytest-dev/pytest/issues/new>`__.

src/_pytest/nose.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
11
""" run test suites written for nose. """
2-
import sys
3-
4-
import pytest
52
from _pytest import python
6-
from _pytest import runner
73
from _pytest import unittest
84
from _pytest.config import hookimpl
95

106

11-
def get_skip_exceptions():
12-
skip_classes = set()
13-
for module_name in ("unittest", "unittest2", "nose"):
14-
mod = sys.modules.get(module_name)
15-
if hasattr(mod, "SkipTest"):
16-
skip_classes.add(mod.SkipTest)
17-
return tuple(skip_classes)
18-
19-
20-
def pytest_runtest_makereport(item, call):
21-
if call.excinfo and call.excinfo.errisinstance(get_skip_exceptions()):
22-
# let's substitute the excinfo with a pytest.skip one
23-
call2 = runner.CallInfo.from_call(
24-
lambda: pytest.skip(str(call.excinfo.value)), call.when
25-
)
26-
call.excinfo = call2.excinfo
27-
28-
297
@hookimpl(trylast=True)
308
def pytest_runtest_setup(item):
319
if is_potential_nosetest(item):
@@ -40,9 +18,6 @@ def teardown_nose(item):
4018
if is_potential_nosetest(item):
4119
if not call_optional(item.obj, "teardown"):
4220
call_optional(item.parent.obj, "teardown")
43-
# if hasattr(item.parent, '_nosegensetup'):
44-
# #call_optional(item._nosegensetup, 'teardown')
45-
# del item.parent._nosegensetup
4621

4722

4823
def is_potential_nosetest(item):

src/_pytest/runner.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,11 @@ def pytest_make_collect_report(collector):
249249
if not call.excinfo:
250250
outcome = "passed"
251251
else:
252-
from _pytest import nose
253-
254-
skip_exceptions = (Skipped,) + nose.get_skip_exceptions()
255-
if call.excinfo.errisinstance(skip_exceptions):
252+
skip_exceptions = [Skipped]
253+
unittest = sys.modules.get("unittest")
254+
if unittest is not None:
255+
skip_exceptions.append(unittest.SkipTest)
256+
if call.excinfo.errisinstance(tuple(skip_exceptions)):
256257
outcome = "skipped"
257258
r = collector._repr_failure_py(call.excinfo, "line").reprcrash
258259
longrepr = (str(r.path), r.lineno, r.message)

src/_pytest/unittest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from _pytest.outcomes import xfail
1212
from _pytest.python import Class
1313
from _pytest.python import Function
14+
from _pytest.runner import CallInfo
1415

1516

1617
def pytest_pycollect_makeitem(collector, name, obj):
@@ -223,6 +224,14 @@ def pytest_runtest_makereport(item, call):
223224
except AttributeError:
224225
pass
225226

227+
unittest = sys.modules.get("unittest")
228+
if unittest and call.excinfo and call.excinfo.errisinstance(unittest.SkipTest):
229+
# let's substitute the excinfo with a pytest.skip one
230+
call2 = CallInfo.from_call(
231+
lambda: pytest.skip(str(call.excinfo.value)), call.when
232+
)
233+
call.excinfo = call2.excinfo
234+
226235

227236
# twisted trial support
228237

testing/test_unittest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,7 @@ def test_should_not_run(self):
939939
reprec.assertoutcome(passed=1)
940940

941941

942-
@pytest.mark.parametrize(
943-
"base", ["builtins.object", "unittest.TestCase", "unittest2.TestCase"]
944-
)
942+
@pytest.mark.parametrize("base", ["builtins.object", "unittest.TestCase"])
945943
def test_usefixtures_marker_on_unittest(base, testdir):
946944
"""#3498"""
947945
module = base.rsplit(".", 1)[0]

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ deps =
4545
pexpect: pexpect
4646
pluggymaster: git+https://github.com/pytest-dev/pluggy.git@master
4747
twisted: twisted
48-
twisted: unittest2
4948
xdist: pytest-xdist>=1.13
5049
{env:_PYTEST_TOX_EXTRA_DEP:}
5150
platform = {env:_PYTEST_TOX_PLATFORM:.*}

0 commit comments

Comments
 (0)