Skip to content

Commit 21c2dcf

Browse files
fixup nose/pytest plugins
1 parent 909ed38 commit 21c2dcf

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

_pytest/nose.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import sys
44

55
import py
6-
import pytest
7-
from _pytest import unittest
6+
from _pytest import unittest, runner, python
7+
from _pytest.config import hookimpl
88

99

1010
def get_skip_exceptions():
@@ -19,19 +19,19 @@ def get_skip_exceptions():
1919
def pytest_runtest_makereport(item, call):
2020
if call.excinfo and call.excinfo.errisinstance(get_skip_exceptions()):
2121
# let's substitute the excinfo with a pytest.skip one
22-
call2 = call.__class__(lambda:
23-
pytest.skip(str(call.excinfo.value)), call.when)
22+
call2 = call.__class__(
23+
lambda: runner.skip(str(call.excinfo.value)), call.when)
2424
call.excinfo = call2.excinfo
2525

2626

27-
@pytest.hookimpl(trylast=True)
27+
@hookimpl(trylast=True)
2828
def pytest_runtest_setup(item):
2929
if is_potential_nosetest(item):
30-
if isinstance(item.parent, pytest.Generator):
30+
if isinstance(item.parent, python.Generator):
3131
gen = item.parent
3232
if not hasattr(gen, '_nosegensetup'):
3333
call_optional(gen.obj, 'setup')
34-
if isinstance(gen.parent, pytest.Instance):
34+
if isinstance(gen.parent, python.Instance):
3535
call_optional(gen.parent.obj, 'setup')
3636
gen._nosegensetup = True
3737
if not call_optional(item.obj, 'setup'):
@@ -50,14 +50,14 @@ def teardown_nose(item):
5050

5151

5252
def pytest_make_collect_report(collector):
53-
if isinstance(collector, pytest.Generator):
53+
if isinstance(collector, python.Generator):
5454
call_optional(collector.obj, 'setup')
5555

5656

5757
def is_potential_nosetest(item):
5858
# extra check needed since we do not do nose style setup/teardown
5959
# on direct unittest style classes
60-
return isinstance(item, pytest.Function) and \
60+
return isinstance(item, python.Function) and \
6161
not isinstance(item, unittest.TestCaseFunction)
6262

6363

_pytest/unittest.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import sys
55
import traceback
66

7-
import pytest
87
# for transferring markers
98
import _pytest._code
10-
from _pytest.python import transfer_markers
11-
from _pytest.skipping import MarkEvaluator
9+
from _pytest.config import hookimpl
10+
from _pytest.runner import fail, skip
11+
from _pytest.python import transfer_markers, Class, Module, Function
12+
from _pytest.skipping import MarkEvaluator, xfail
1213

1314

1415
def pytest_pycollect_makeitem(collector, name, obj):
@@ -22,11 +23,11 @@ def pytest_pycollect_makeitem(collector, name, obj):
2223
return UnitTestCase(name, parent=collector)
2324

2425

25-
class UnitTestCase(pytest.Class):
26+
class UnitTestCase(Class):
2627
# marker for fixturemanger.getfixtureinfo()
2728
# to declare that our children do not support funcargs
2829
nofuncargs = True
29-
30+
3031
def setup(self):
3132
cls = self.obj
3233
if getattr(cls, '__unittest_skip__', False):
@@ -46,7 +47,7 @@ def collect(self):
4647
return
4748
self.session._fixturemanager.parsefactories(self, unittest=True)
4849
loader = TestLoader()
49-
module = self.getparent(pytest.Module).obj
50+
module = self.getparent(Module).obj
5051
foundsomething = False
5152
for name in loader.getTestCaseNames(self.obj):
5253
x = getattr(self.obj, name)
@@ -65,7 +66,7 @@ def collect(self):
6566
yield TestCaseFunction('runTest', parent=self)
6667

6768

68-
class TestCaseFunction(pytest.Function):
69+
class TestCaseFunction(Function):
6970
_excinfo = None
7071

7172
def setup(self):
@@ -110,36 +111,37 @@ def _addexcinfo(self, rawexcinfo):
110111
try:
111112
l = traceback.format_exception(*rawexcinfo)
112113
l.insert(0, "NOTE: Incompatible Exception Representation, "
113-
"displaying natively:\n\n")
114-
pytest.fail("".join(l), pytrace=False)
115-
except (pytest.fail.Exception, KeyboardInterrupt):
114+
"displaying natively:\n\n")
115+
fail("".join(l), pytrace=False)
116+
except (fail.Exception, KeyboardInterrupt):
116117
raise
117118
except:
118-
pytest.fail("ERROR: Unknown Incompatible Exception "
119-
"representation:\n%r" %(rawexcinfo,), pytrace=False)
119+
fail("ERROR: Unknown Incompatible Exception "
120+
"representation:\n%r" % (rawexcinfo,), pytrace=False)
120121
except KeyboardInterrupt:
121122
raise
122-
except pytest.fail.Exception:
123+
except fail.Exception:
123124
excinfo = _pytest._code.ExceptionInfo()
124125
self.__dict__.setdefault('_excinfo', []).append(excinfo)
125126

126127
def addError(self, testcase, rawexcinfo):
127128
self._addexcinfo(rawexcinfo)
129+
128130
def addFailure(self, testcase, rawexcinfo):
129131
self._addexcinfo(rawexcinfo)
130132

131133
def addSkip(self, testcase, reason):
132134
try:
133-
pytest.skip(reason)
134-
except pytest.skip.Exception:
135+
skip(reason)
136+
except skip.Exception:
135137
self._evalskip = MarkEvaluator(self, 'SkipTest')
136138
self._evalskip.result = True
137139
self._addexcinfo(sys.exc_info())
138140

139141
def addExpectedFailure(self, testcase, rawexcinfo, reason=""):
140142
try:
141-
pytest.xfail(str(reason))
142-
except pytest.xfail.Exception:
143+
xfail(str(reason))
144+
except xfail.Exception:
143145
self._addexcinfo(sys.exc_info())
144146

145147
def addUnexpectedSuccess(self, testcase, reason=""):
@@ -179,13 +181,14 @@ def runtest(self):
179181
self._testcase.debug()
180182

181183
def _prunetraceback(self, excinfo):
182-
pytest.Function._prunetraceback(self, excinfo)
184+
Function._prunetraceback(self, excinfo)
183185
traceback = excinfo.traceback.filter(
184-
lambda x:not x.frame.f_globals.get('__unittest'))
186+
lambda x: not x.frame.f_globals.get('__unittest'))
185187
if traceback:
186188
excinfo.traceback = traceback
187189

188-
@pytest.hookimpl(tryfirst=True)
190+
191+
@hookimpl(tryfirst=True)
189192
def pytest_runtest_makereport(item, call):
190193
if isinstance(item, TestCaseFunction):
191194
if item._excinfo:
@@ -197,7 +200,8 @@ def pytest_runtest_makereport(item, call):
197200

198201
# twisted trial support
199202

200-
@pytest.hookimpl(hookwrapper=True)
203+
204+
@hookimpl(hookwrapper=True)
201205
def pytest_runtest_protocol(item):
202206
if isinstance(item, TestCaseFunction) and \
203207
'twisted.trial.unittest' in sys.modules:

0 commit comments

Comments
 (0)