3
3
4
4
import py
5
5
6
+ from _pytest ._code .code import ExceptionChainRepr
6
7
from _pytest ._code .code import ExceptionInfo
7
8
from _pytest ._code .code import ReprEntry
8
9
from _pytest ._code .code import ReprEntryNative
@@ -160,7 +161,7 @@ def _to_json(self):
160
161
161
162
Experimental method.
162
163
"""
163
- return _test_report_to_json (self )
164
+ return _report_to_json (self )
164
165
165
166
@classmethod
166
167
def _from_json (cls , reportdict ):
@@ -172,7 +173,7 @@ def _from_json(cls, reportdict):
172
173
173
174
Experimental method.
174
175
"""
175
- kwargs = _test_report_kwargs_from_json (reportdict )
176
+ kwargs = _report_kwargs_from_json (reportdict )
176
177
return cls (** kwargs )
177
178
178
179
@@ -340,7 +341,7 @@ def pytest_report_from_serializable(data):
340
341
)
341
342
342
343
343
- def _test_report_to_json ( test_report ):
344
+ def _report_to_json ( report ):
344
345
"""
345
346
This was originally the serialize_report() function from xdist (ca03269).
346
347
@@ -366,22 +367,35 @@ def serialize_repr_crash(reprcrash):
366
367
return reprcrash .__dict__ .copy ()
367
368
368
369
def serialize_longrepr (rep ):
369
- return {
370
+ result = {
370
371
"reprcrash" : serialize_repr_crash (rep .longrepr .reprcrash ),
371
372
"reprtraceback" : serialize_repr_traceback (rep .longrepr .reprtraceback ),
372
373
"sections" : rep .longrepr .sections ,
373
374
}
375
+ if isinstance (rep .longrepr , ExceptionChainRepr ):
376
+ result ["chain" ] = []
377
+ for repr_traceback , repr_crash , description in rep .longrepr .chain :
378
+ result ["chain" ].append (
379
+ (
380
+ serialize_repr_traceback (repr_traceback ),
381
+ serialize_repr_crash (repr_crash ),
382
+ description ,
383
+ )
384
+ )
385
+ else :
386
+ result ["chain" ] = None
387
+ return result
374
388
375
- d = test_report .__dict__ .copy ()
376
- if hasattr (test_report .longrepr , "toterminal" ):
377
- if hasattr (test_report .longrepr , "reprtraceback" ) and hasattr (
378
- test_report .longrepr , "reprcrash"
389
+ d = report .__dict__ .copy ()
390
+ if hasattr (report .longrepr , "toterminal" ):
391
+ if hasattr (report .longrepr , "reprtraceback" ) and hasattr (
392
+ report .longrepr , "reprcrash"
379
393
):
380
- d ["longrepr" ] = serialize_longrepr (test_report )
394
+ d ["longrepr" ] = serialize_longrepr (report )
381
395
else :
382
- d ["longrepr" ] = str (test_report .longrepr )
396
+ d ["longrepr" ] = str (report .longrepr )
383
397
else :
384
- d ["longrepr" ] = test_report .longrepr
398
+ d ["longrepr" ] = report .longrepr
385
399
for name in d :
386
400
if isinstance (d [name ], (py .path .local , Path )):
387
401
d [name ] = str (d [name ])
@@ -390,12 +404,11 @@ def serialize_longrepr(rep):
390
404
return d
391
405
392
406
393
- def _test_report_kwargs_from_json (reportdict ):
407
+ def _report_kwargs_from_json (reportdict ):
394
408
"""
395
409
This was originally the serialize_report() function from xdist (ca03269).
396
410
397
- Factory method that returns either a TestReport or CollectReport, depending on the calling
398
- class. It's the callers responsibility to know which class to pass here.
411
+ Returns **kwargs that can be used to construct a TestReport or CollectReport instance.
399
412
"""
400
413
401
414
def deserialize_repr_entry (entry_data ):
@@ -439,12 +452,26 @@ def deserialize_repr_crash(repr_crash_dict):
439
452
and "reprcrash" in reportdict ["longrepr" ]
440
453
and "reprtraceback" in reportdict ["longrepr" ]
441
454
):
442
- exception_info = ReprExceptionInfo (
443
- reprtraceback = deserialize_repr_traceback (
444
- reportdict ["longrepr" ]["reprtraceback" ]
445
- ),
446
- reprcrash = deserialize_repr_crash (reportdict ["longrepr" ]["reprcrash" ]),
455
+
456
+ reprtraceback = deserialize_repr_traceback (
457
+ reportdict ["longrepr" ]["reprtraceback" ]
447
458
)
459
+ reprcrash = deserialize_repr_crash (reportdict ["longrepr" ]["reprcrash" ])
460
+ if reportdict ["longrepr" ]["chain" ]:
461
+ chain = []
462
+ for repr_traceback_data , repr_crash_data , description in reportdict [
463
+ "longrepr"
464
+ ]["chain" ]:
465
+ chain .append (
466
+ (
467
+ deserialize_repr_traceback (repr_traceback_data ),
468
+ deserialize_repr_crash (repr_crash_data ),
469
+ description ,
470
+ )
471
+ )
472
+ exception_info = ExceptionChainRepr (chain )
473
+ else :
474
+ exception_info = ReprExceptionInfo (reprtraceback , reprcrash )
448
475
449
476
for section in reportdict ["longrepr" ]["sections" ]:
450
477
exception_info .addsection (* section )
0 commit comments