Remove support code for unittest 2
Also moved a pytest_runtest_makereport hook implemented in nose.py, but nowadays makes more sense to be implemented in unittest.py
This commit is contained in:
@@ -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()):
|
||||
# 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):
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,6 +11,7 @@ from _pytest.outcomes import skip
|
||||
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):
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user