@@ -133,16 +133,14 @@ def pytest_runtest_call(item):
133
133
pass
134
134
try :
135
135
item .runtest ()
136
- except Exception :
136
+ except Exception as e :
137
137
# Store trace info to allow postmortem debugging
138
- type , value , tb = sys .exc_info ()
139
- assert tb is not None
140
- tb = tb .tb_next # Skip *this* frame
141
- sys .last_type = type
142
- sys .last_value = value
143
- sys .last_traceback = tb
144
- del type , value , tb # Get rid of these in this frame
145
- raise
138
+ sys .last_type = type (e )
139
+ sys .last_value = e
140
+ assert e .__traceback__ is not None
141
+ # Skip *this* frame
142
+ sys .last_traceback = e .__traceback__ .tb_next
143
+ raise e
146
144
147
145
148
146
def pytest_runtest_teardown (item , nextitem ):
@@ -318,15 +316,13 @@ def _callfinalizers(self, colitem):
318
316
fin = finalizers .pop ()
319
317
try :
320
318
fin ()
321
- except TEST_OUTCOME :
319
+ except TEST_OUTCOME as e :
322
320
# XXX Only first exception will be seen by user,
323
321
# ideally all should be reported.
324
322
if exc is None :
325
- exc = sys . exc_info ()
323
+ exc = e
326
324
if exc :
327
- _ , val , tb = exc
328
- assert val is not None
329
- raise val .with_traceback (tb )
325
+ raise exc
330
326
331
327
def _teardown_with_finalization (self , colitem ):
332
328
self ._callfinalizers (colitem )
@@ -352,15 +348,13 @@ def _teardown_towards(self, needed_collectors):
352
348
break
353
349
try :
354
350
self ._pop_and_teardown ()
355
- except TEST_OUTCOME :
351
+ except TEST_OUTCOME as e :
356
352
# XXX Only first exception will be seen by user,
357
353
# ideally all should be reported.
358
354
if exc is None :
359
- exc = sys . exc_info ()
355
+ exc = e
360
356
if exc :
361
- _ , val , tb = exc
362
- assert val is not None
363
- raise val .with_traceback (tb )
357
+ raise exc
364
358
365
359
def prepare (self , colitem ):
366
360
""" setup objects along the collector chain to the test-method
@@ -371,15 +365,15 @@ def prepare(self, colitem):
371
365
# check if the last collection node has raised an error
372
366
for col in self .stack :
373
367
if hasattr (col , "_prepare_exc" ):
374
- _ , val , tb = col ._prepare_exc
375
- raise val . with_traceback ( tb )
368
+ exc = col ._prepare_exc
369
+ raise exc
376
370
for col in needed_collectors [len (self .stack ) :]:
377
371
self .stack .append (col )
378
372
try :
379
373
col .setup ()
380
- except TEST_OUTCOME :
381
- col ._prepare_exc = sys . exc_info ()
382
- raise
374
+ except TEST_OUTCOME as e :
375
+ col ._prepare_exc = e
376
+ raise e
383
377
384
378
385
379
def collect_one_node (collector ):
0 commit comments