44import sys
55import traceback
66
7- import pytest
87# for transferring markers
98import _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
1415def 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 )
189192def 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 )
201205def pytest_runtest_protocol (item ):
202206 if isinstance (item , TestCaseFunction ) and \
203207 'twisted.trial.unittest' in sys .modules :
0 commit comments