@@ -71,7 +71,7 @@ def test_excinfo_simple():
71
71
try :
72
72
raise ValueError
73
73
except ValueError :
74
- info = _pytest ._code .ExceptionInfo ()
74
+ info = _pytest ._code .ExceptionInfo . from_current ()
75
75
assert info .type == ValueError
76
76
77
77
@@ -85,7 +85,7 @@ def f():
85
85
try :
86
86
f ()
87
87
except ValueError :
88
- excinfo = _pytest ._code .ExceptionInfo ()
88
+ excinfo = _pytest ._code .ExceptionInfo . from_current ()
89
89
linenumbers = [
90
90
_pytest ._code .getrawcode (f ).co_firstlineno - 1 + 4 ,
91
91
_pytest ._code .getrawcode (f ).co_firstlineno - 1 + 1 ,
@@ -126,7 +126,7 @@ def setup_method(self, method):
126
126
try :
127
127
h ()
128
128
except ValueError :
129
- self .excinfo = _pytest ._code .ExceptionInfo ()
129
+ self .excinfo = _pytest ._code .ExceptionInfo . from_current ()
130
130
131
131
def test_traceback_entries (self ):
132
132
tb = self .excinfo .traceback
@@ -163,7 +163,7 @@ def xyz():
163
163
try :
164
164
exec (source .compile ())
165
165
except NameError :
166
- tb = _pytest ._code .ExceptionInfo ().traceback
166
+ tb = _pytest ._code .ExceptionInfo . from_current ().traceback
167
167
print (tb [- 1 ].getsource ())
168
168
s = str (tb [- 1 ].getsource ())
169
169
assert s .startswith ("def xyz():\n try:" )
@@ -356,6 +356,12 @@ def test_excinfo_str():
356
356
assert len (s .split (":" )) >= 3 # on windows it's 4
357
357
358
358
359
+ def test_excinfo_for_later ():
360
+ e = ExceptionInfo .for_later ()
361
+ assert "for raises" in repr (e )
362
+ assert "for raises" in str (e )
363
+
364
+
359
365
def test_excinfo_errisinstance ():
360
366
excinfo = pytest .raises (ValueError , h )
361
367
assert excinfo .errisinstance (ValueError )
@@ -365,7 +371,7 @@ def test_excinfo_no_sourcecode():
365
371
try :
366
372
exec ("raise ValueError()" )
367
373
except ValueError :
368
- excinfo = _pytest ._code .ExceptionInfo ()
374
+ excinfo = _pytest ._code .ExceptionInfo . from_current ()
369
375
s = str (excinfo .traceback [- 1 ])
370
376
assert s == " File '<string>':1 in <module>\n ???\n "
371
377
@@ -390,7 +396,7 @@ def test_entrysource_Queue_example():
390
396
try :
391
397
queue .Queue ().get (timeout = 0.001 )
392
398
except queue .Empty :
393
- excinfo = _pytest ._code .ExceptionInfo ()
399
+ excinfo = _pytest ._code .ExceptionInfo . from_current ()
394
400
entry = excinfo .traceback [- 1 ]
395
401
source = entry .getsource ()
396
402
assert source is not None
@@ -402,7 +408,7 @@ def test_codepath_Queue_example():
402
408
try :
403
409
queue .Queue ().get (timeout = 0.001 )
404
410
except queue .Empty :
405
- excinfo = _pytest ._code .ExceptionInfo ()
411
+ excinfo = _pytest ._code .ExceptionInfo . from_current ()
406
412
entry = excinfo .traceback [- 1 ]
407
413
path = entry .path
408
414
assert isinstance (path , py .path .local )
@@ -453,7 +459,7 @@ def excinfo_from_exec(self, source):
453
459
except KeyboardInterrupt :
454
460
raise
455
461
except : # noqa
456
- return _pytest ._code .ExceptionInfo ()
462
+ return _pytest ._code .ExceptionInfo . from_current ()
457
463
assert 0 , "did not raise"
458
464
459
465
def test_repr_source (self ):
@@ -491,7 +497,7 @@ def test_repr_source_not_existing(self):
491
497
try :
492
498
exec (co )
493
499
except ValueError :
494
- excinfo = _pytest ._code .ExceptionInfo ()
500
+ excinfo = _pytest ._code .ExceptionInfo . from_current ()
495
501
repr = pr .repr_excinfo (excinfo )
496
502
assert repr .reprtraceback .reprentries [1 ].lines [0 ] == "> ???"
497
503
if sys .version_info [0 ] >= 3 :
@@ -510,7 +516,7 @@ def test_repr_many_line_source_not_existing(self):
510
516
try :
511
517
exec (co )
512
518
except ValueError :
513
- excinfo = _pytest ._code .ExceptionInfo ()
519
+ excinfo = _pytest ._code .ExceptionInfo . from_current ()
514
520
repr = pr .repr_excinfo (excinfo )
515
521
assert repr .reprtraceback .reprentries [1 ].lines [0 ] == "> ???"
516
522
if sys .version_info [0 ] >= 3 :
@@ -1340,7 +1346,7 @@ def test_repr_traceback_with_unicode(style, encoding):
1340
1346
try :
1341
1347
raise RuntimeError (msg )
1342
1348
except RuntimeError :
1343
- e_info = ExceptionInfo ()
1349
+ e_info = ExceptionInfo . from_current ()
1344
1350
formatter = FormattedExcinfo (style = style )
1345
1351
repr_traceback = formatter .repr_traceback (e_info )
1346
1352
assert repr_traceback is not None
0 commit comments