Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop unittest2 support #5565

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions changelog/5565.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Removed unused support code for `unittest2 <https://pypi.org/project/unittest2/>`__.

The ``unittest2`` backport module is no longer
necessary since Python 3.3+, and the small amount of code in pytest to support it also doesn't seem
to be used: after removed, all tests still pass unchanged.

Although our policy is to introduce a deprecation period before removing any features or support
for third party libraries, because this code is apparently not used
at all (even if ``unittest2`` is used by a test suite executed by pytest), it was decided to
remove it in this release.

If you experience a regression because of this, please
`file an issue <https://github.com/pytest-dev/pytest/issues/new>`__.
25 changes: 0 additions & 25 deletions src/_pytest/nose.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
""" run test suites written for nose. """
import sys

import pytest
from _pytest import python
from _pytest import runner
from _pytest import unittest
from _pytest.config import hookimpl


def get_skip_exceptions():
skip_classes = set()
for module_name in ("unittest", "unittest2", "nose"):
mod = sys.modules.get(module_name)
if hasattr(mod, "SkipTest"):
skip_classes.add(mod.SkipTest)
return tuple(skip_classes)


def pytest_runtest_makereport(item, call):
if call.excinfo and call.excinfo.errisinstance(get_skip_exceptions()):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was moved to unittest.py as I think it makes more sense there.

# let's substitute the excinfo with a pytest.skip one
call2 = runner.CallInfo.from_call(
lambda: pytest.skip(str(call.excinfo.value)), call.when
)
call.excinfo = call2.excinfo


@hookimpl(trylast=True)
def pytest_runtest_setup(item):
if is_potential_nosetest(item):
Expand All @@ -40,9 +18,6 @@ def teardown_nose(item):
if is_potential_nosetest(item):
if not call_optional(item.obj, "teardown"):
call_optional(item.parent.obj, "teardown")
# if hasattr(item.parent, '_nosegensetup'):
# #call_optional(item._nosegensetup, 'teardown')
# del item.parent._nosegensetup


def is_potential_nosetest(item):
Expand Down
9 changes: 5 additions & 4 deletions src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,11 @@ def pytest_make_collect_report(collector):
if not call.excinfo:
outcome = "passed"
else:
from _pytest import nose

skip_exceptions = (Skipped,) + nose.get_skip_exceptions()
if call.excinfo.errisinstance(skip_exceptions):
skip_exceptions = [Skipped]
unittest = sys.modules.get("unittest")
if unittest is not None:
skip_exceptions.append(unittest.SkipTest)
if call.excinfo.errisinstance(tuple(skip_exceptions)):
outcome = "skipped"
r = collector._repr_failure_py(call.excinfo, "line").reprcrash
longrepr = (str(r.path), r.lineno, r.message)
Expand Down
9 changes: 9 additions & 0 deletions src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from _pytest.outcomes import xfail
from _pytest.python import Class
from _pytest.python import Function
from _pytest.runner import CallInfo


def pytest_pycollect_makeitem(collector, name, obj):
Expand Down Expand Up @@ -223,6 +224,14 @@ def pytest_runtest_makereport(item, call):
except AttributeError:
pass

unittest = sys.modules.get("unittest")
if unittest and call.excinfo and call.excinfo.errisinstance(unittest.SkipTest):
# let's substitute the excinfo with a pytest.skip one
call2 = CallInfo.from_call(
lambda: pytest.skip(str(call.excinfo.value)), call.when
)
call.excinfo = call2.excinfo


# twisted trial support

Expand Down
4 changes: 1 addition & 3 deletions testing/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,7 @@ def test_should_not_run(self):
reprec.assertoutcome(passed=1)


@pytest.mark.parametrize(
"base", ["builtins.object", "unittest.TestCase", "unittest2.TestCase"]
)
@pytest.mark.parametrize("base", ["builtins.object", "unittest.TestCase"])
def test_usefixtures_marker_on_unittest(base, testdir):
"""#3498"""
module = base.rsplit(".", 1)[0]
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ deps =
pexpect: pexpect
pluggymaster: git+https://github.com/pytest-dev/pluggy.git@master
twisted: twisted
twisted: unittest2
xdist: pytest-xdist>=1.13
{env:_PYTEST_TOX_EXTRA_DEP:}
platform = {env:_PYTEST_TOX_PLATFORM:.*}
Expand Down