Skip to content

Commit 03440ce

Browse files
fixup nose/pytest plugins
1 parent 56cdd74 commit 03440ce

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
@@ -4,8 +4,8 @@
44
import sys
55

66
import py
7-
import pytest
8-
from _pytest import unittest
7+
from _pytest import unittest, runner, python
8+
from _pytest.config import hookimpl
99

1010

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

2727

28-
@pytest.hookimpl(trylast=True)
28+
@hookimpl(trylast=True)
2929
def pytest_runtest_setup(item):
3030
if is_potential_nosetest(item):
31-
if isinstance(item.parent, pytest.Generator):
31+
if isinstance(item.parent, python.Generator):
3232
gen = item.parent
3333
if not hasattr(gen, '_nosegensetup'):
3434
call_optional(gen.obj, 'setup')
35-
if isinstance(gen.parent, pytest.Instance):
35+
if isinstance(gen.parent, python.Instance):
3636
call_optional(gen.parent.obj, 'setup')
3737
gen._nosegensetup = True
3838
if not call_optional(item.obj, 'setup'):
@@ -51,14 +51,14 @@ def teardown_nose(item):
5151

5252

5353
def pytest_make_collect_report(collector):
54-
if isinstance(collector, pytest.Generator):
54+
if isinstance(collector, python.Generator):
5555
call_optional(collector.obj, 'setup')
5656

5757

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

6464

_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)