@@ -223,13 +223,26 @@ def pytest_report_teststatus(report: BaseReport) -> Optional[Tuple[str, str, str
223
223
def call_and_report (
224
224
item : Item , when : Literal ["setup" , "call" , "teardown" ], log : bool = True , ** kwds
225
225
) -> TestReport :
226
- call = call_runtest_hook (item , when , ** kwds )
227
- hook = item .ihook
228
- report : TestReport = hook .pytest_runtest_makereport (item = item , call = call )
226
+ ihook = item .ihook
227
+ if when == "setup" :
228
+ runtest_hook : Callable [..., None ] = ihook .pytest_runtest_setup
229
+ elif when == "call" :
230
+ runtest_hook = ihook .pytest_runtest_call
231
+ elif when == "teardown" :
232
+ runtest_hook = ihook .pytest_runtest_teardown
233
+ else :
234
+ assert False , f"Unhandled runtest hook case: { when } "
235
+ reraise : Tuple [Type [BaseException ], ...] = (Exit ,)
236
+ if not item .config .getoption ("usepdb" , False ):
237
+ reraise += (KeyboardInterrupt ,)
238
+ call = CallInfo .from_call (
239
+ lambda : runtest_hook (item = item , ** kwds ), when = when , reraise = reraise
240
+ )
241
+ report : TestReport = ihook .pytest_runtest_makereport (item = item , call = call )
229
242
if log :
230
- hook .pytest_runtest_logreport (report = report )
243
+ ihook .pytest_runtest_logreport (report = report )
231
244
if check_interactive_exception (call , report ):
232
- hook .pytest_exception_interact (node = item , call = call , report = report )
245
+ ihook .pytest_exception_interact (node = item , call = call , report = report )
233
246
return report
234
247
235
248
@@ -248,25 +261,6 @@ def check_interactive_exception(call: "CallInfo[object]", report: BaseReport) ->
248
261
return True
249
262
250
263
251
- def call_runtest_hook (
252
- item : Item , when : Literal ["setup" , "call" , "teardown" ], ** kwds
253
- ) -> "CallInfo[None]" :
254
- if when == "setup" :
255
- ihook : Callable [..., None ] = item .ihook .pytest_runtest_setup
256
- elif when == "call" :
257
- ihook = item .ihook .pytest_runtest_call
258
- elif when == "teardown" :
259
- ihook = item .ihook .pytest_runtest_teardown
260
- else :
261
- assert False , f"Unhandled runtest hook case: { when } "
262
- reraise : Tuple [Type [BaseException ], ...] = (Exit ,)
263
- if not item .config .getoption ("usepdb" , False ):
264
- reraise += (KeyboardInterrupt ,)
265
- return CallInfo .from_call (
266
- lambda : ihook (item = item , ** kwds ), when = when , reraise = reraise
267
- )
268
-
269
-
270
264
TResult = TypeVar ("TResult" , covariant = True )
271
265
272
266
0 commit comments