| 184 | 184 | "sections": rep.longrepr.sections, |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | def disassembled_chain_report(rep): | |
| 188 | """Serialize ExceptionChainRepr objects.""" | |
| 189 | from _pytest._code.code import ExceptionChainRepr | |
| 190 | ||
| 191 | chain_data = [] | |
| 192 | for reprtraceback, reprcrash, descr in rep.longrepr.chain: | |
| 193 | # Serialize reprtraceback | |
| 194 | reprtraceback_dict = reprtraceback.__dict__.copy() | |
| 195 | new_entries = [] | |
| 196 | for entry in reprtraceback_dict["reprentries"]: | |
| 197 | entry_data = { | |
| 198 | "type": type(entry).__name__, | |
| 199 | "data": entry.__dict__.copy(), | |
| 200 | } | |
| 201 | for key, value in entry_data["data"].items(): | |
| 202 | if hasattr(value, "__dict__"): | |
| 203 | entry_data["data"][key] = value.__dict__.copy() | |
| 204 | new_entries.append(entry_data) | |
| 205 | reprtraceback_dict["reprentries"] = new_entries | |
| 206 | ||
| 207 | # Serialize reprcrash | |
| 208 | reprcrash_dict = reprcrash.__dict__.copy() if reprcrash else None | |
| 209 | ||
| 210 | chain_data.append({ | |
| 211 | "reprtraceback": reprtraceback_dict, | |
| 212 | "reprcrash": reprcrash_dict, | |
| 213 | "descr": descr, | |
| 214 | }) | |
| 215 | ||
| 216 | return { | |
| 217 | "chain": chain_data, | |
| 218 | "sections": rep.longrepr.sections, | |
| 219 | } | |
| 220 | ||
| 187 | 221 | d = self.__dict__.copy() |
| 188 | 222 | if hasattr(self.longrepr, "toterminal"): |
| 189 | if hasattr(self.longrepr, "reprtraceback") and hasattr( | |
| 223 | # Check if this is an ExceptionChainRepr | |
| 224 | from _pytest._code.code import ExceptionChainRepr | |
| 225 | print(f"DEBUG: longrepr type = {type(self.longrepr)}") | |
| 226 | print(f"DEBUG: isinstance ExceptionChainRepr = {isinstance(self.longrepr, ExceptionChainRepr)}") | |
| 227 | print(f"DEBUG: hasattr reprtraceback = {hasattr(self.longrepr, 'reprtraceback')}") | |
| 228 | print(f"DEBUG: hasattr reprcrash = {hasattr(self.longrepr, 'reprcrash')}") | |
| 229 | print(f"DEBUG: hasattr chain = {hasattr(self.longrepr, 'chain')}") | |
| 230 | if isinstance(self.longrepr, ExceptionChainRepr): | |
| 231 | print("DEBUG: Using disassembled_chain_report") | |
| 232 | d["longrepr"] = disassembled_chain_report(self) | |
| 233 | d["longrepr"]["_type"] = "ExceptionChainRepr" | |
| 234 | elif hasattr(self.longrepr, "reprtraceback") and hasattr( | |
| 190 | 235 | self.longrepr, "reprcrash" |
| 191 | 236 | ): |
| 237 | print("DEBUG: Using disassembled_report") | |
| 192 | 238 | d["longrepr"] = disassembled_report(self) |
| 239 | d["longrepr"]["_type"] = "ReprExceptionInfo" | |
| 193 | 240 | else: |
| 241 | print("DEBUG: Using str conversion") | |
| 194 | 242 | d["longrepr"] = str(self.longrepr) |
| 195 | 243 | else: |
| 196 | 244 | d["longrepr"] = self.longrepr |
| 212 | 260 | Experimental method. |
| 213 | 261 | """ |
| 214 | 262 | if reportdict["longrepr"]: |
| 215 | if ( | |
| 216 | "reprcrash" in reportdict["longrepr"] | |
| 217 | and "reprtraceback" in reportdict["longrepr"] | |
| 218 | ): | |
| 219 | ||
| 220 | reprtraceback = reportdict["longrepr"]["reprtraceback"] | |
| 221 | reprcrash = reportdict["longrepr"]["reprcrash"] | |
| 222 | ||
| 223 | unserialized_entries = [] | |
| 224 | reprentry = None | |
| 225 | for entry_data in reprtraceback["reprentries"]: | |
| 226 | data = entry_data["data"] | |
| 227 | entry_type = entry_data["type"] | |
| 228 | if entry_type == "ReprEntry": | |
| 229 | reprfuncargs = None | |
| 230 | reprfileloc = None | |
| 231 | reprlocals = None | |
| 232 | if data["reprfuncargs"]: | |
| 233 | reprfuncargs = ReprFuncArgs(**data["reprfuncargs"]) | |
| 234 | if data["reprfileloc"]: | |
| 235 | reprfileloc = ReprFileLocation(**data["reprfileloc"]) | |
| 236 | if data["reprlocals"]: | |
| 237 | reprlocals = ReprLocals(data["reprlocals"]["lines"]) | |
| 238 | ||
| 239 | reprentry = ReprEntry( | |
| 240 | lines=data["lines"], | |
| 241 | reprfuncargs=reprfuncargs, | |
| 242 | reprlocals=reprlocals, | |
| 243 | filelocrepr=reprfileloc, | |
| 244 | style=data["style"], | |
| 245 | ) | |
| 246 | elif entry_type == "ReprEntryNative": | |
| 247 | reprentry = ReprEntryNative(data["lines"]) | |
| 248 | else: | |
| 249 | _report_unserialization_failure(entry_type, cls, reportdict) | |
| 250 | unserialized_entries.append(reprentry) | |
| 251 | reprtraceback["reprentries"] = unserialized_entries | |
| 252 | ||
| 253 | exception_info = ReprExceptionInfo( | |
| 254 | reprtraceback=ReprTraceback(**reprtraceback), | |
| 255 | reprcrash=ReprFileLocation(**reprcrash), | |
| 256 | ) | |
| 257 | ||
| 258 | for section in reportdict["longrepr"]["sections"]: | |
| 263 | longrepr_data = reportdict["longrepr"] | |
| 264 | ||
| 265 | # Check if this is a serialized ExceptionChainRepr | |
| 266 | if isinstance(longrepr_data, dict) and longrepr_data.get("_type") == "ExceptionChainRepr": | |
| 267 | from _pytest._code.code import ExceptionChainRepr, ReprTraceback, ReprFileLocation | |
| 268 | ||
| 269 | # Deserialize the chain | |
| 270 | chain = [] | |
| 271 | for chain_item in longrepr_data["chain"]: | |
| 272 | # Deserialize reprtraceback | |
| 273 | reprtraceback_data = chain_item["reprtraceback"] | |
| 274 | unserialized_entries = [] | |
| 275 | for entry_data in reprtraceback_data["reprentries"]: | |
| 276 | data = entry_data["data"] | |
| 277 | entry_type = entry_data["type"] | |
| 278 | if entry_type == "ReprEntry": | |
| 279 | reprfuncargs = None | |
| 280 | reprfileloc = None | |
| 281 | reprlocals = None | |
| 282 | if data["reprfuncargs"]: | |
| 283 | reprfuncargs = ReprFuncArgs(**data["reprfuncargs"]) | |
| 284 | if data["reprfileloc"]: | |
| 285 | reprfileloc = ReprFileLocation(**data["reprfileloc"]) | |
| 286 | if data["reprlocals"]: | |
| 287 | reprlocals = ReprLocals(data["reprlocals"]["lines"]) | |
| 288 | ||
| 289 | reprentry = ReprEntry( | |
| 290 | lines=data["lines"], | |
| 291 | reprfuncargs=reprfuncargs, | |
| 292 | reprlocals=reprlocals, | |
| 293 | filelocrepr=reprfileloc, | |
| 294 | style=data["style"], | |
| 295 | ) | |
| 296 | elif entry_type == "ReprEntryNative": | |
| 297 | reprentry = ReprEntryNative(data["lines"]) | |
| 298 | else: | |
| 299 | _report_unserialization_failure(entry_type, cls, reportdict) | |
| 300 | unserialized_entries.append(reprentry) | |
| 301 | reprtraceback_data["reprentries"] = unserialized_entries | |
| 302 | reprtraceback = ReprTraceback(**reprtraceback_data) | |
| 303 | ||
| 304 | # Deserialize reprcrash | |
| 305 | reprcrash_data = chain_item["reprcrash"] | |
| 306 | reprcrash = ReprFileLocation(**reprcrash_data) if reprcrash_data else None | |
| 307 | ||
| 308 | # Add to chain | |
| 309 | chain.append((reprtraceback, reprcrash, chain_item["descr"])) | |
| 310 | ||
| 311 | # Create ExceptionChainRepr | |
| 312 | exception_info = ExceptionChainRepr(chain) | |
| 313 | ||
| 314 | # Add sections | |
| 315 | for section in longrepr_data["sections"]: | |
| 259 | 316 | exception_info.addsection(*section) |
| 260 | 317 | reportdict["longrepr"] = exception_info |
| 318 | ||
| 319 | elif isinstance(longrepr_data, dict) and longrepr_data.get("_type") == "ReprExceptionInfo": | |
| 320 | # Handle regular ReprExceptionInfo (remove the _type field before processing) | |
| 321 | longrepr_data.pop("_type", None) | |
| 322 | ||
| 323 | if ( | |
| 324 | "reprcrash" in longrepr_data | |
| 325 | and "reprtraceback" in longrepr_data | |
| 326 | ): | |
| 327 | reprtraceback = longrepr_data["reprtraceback"] | |
| 328 | reprcrash = longrepr_data["reprcrash"] | |
| 329 | ||
| 330 | unserialized_entries = [] | |
| 331 | reprentry = None | |
| 332 | for entry_data in reprtraceback["reprentries"]: | |
| 333 | data = entry_data["data"] | |
| 334 | entry_type = entry_data["type"] | |
| 335 | if entry_type == "ReprEntry": | |
| 336 | reprfuncargs = None | |
| 337 | reprfileloc = None | |
| 338 | reprlocals = None | |
| 339 | if data["reprfuncargs"]: | |
| 340 | reprfuncargs = ReprFuncArgs(**data["reprfuncargs"]) | |
| 341 | if data["reprfileloc"]: | |
| 342 | reprfileloc = ReprFileLocation(**data["reprfileloc"]) | |
| 343 | if data["reprlocals"]: | |
| 344 | reprlocals = ReprLocals(data["reprlocals"]["lines"]) | |
| 345 | ||
| 346 | reprentry = ReprEntry( | |
| 347 | lines=data["lines"], | |
| 348 | reprfuncargs=reprfuncargs, | |
| 349 | reprlocals=reprlocals, | |
| 350 | filelocrepr=reprfileloc, | |
| 351 | style=data["style"], | |
| 352 | ) | |
| 353 | elif entry_type == "ReprEntryNative": | |
| 354 | reprentry = ReprEntryNative(data["lines"]) | |
| 355 | else: | |
| 356 | _report_unserialization_failure(entry_type, cls, reportdict) | |
| 357 | unserialized_entries.append(reprentry) | |
| 358 | reprtraceback["reprentries"] = unserialized_entries | |
| 359 | ||
| 360 | exception_info = ReprExceptionInfo( | |
| 361 | reprtraceback=ReprTraceback(**reprtraceback), | |
| 362 | reprcrash=ReprFileLocation(**reprcrash), | |
| 363 | ) | |
| 364 | ||
| 365 | for section in longrepr_data["sections"]: | |
| 366 | exception_info.addsection(*section) | |
| 367 | reportdict["longrepr"] = exception_info | |
| 261 | 368 | |
| 262 | 369 | return cls(**reportdict) |
| 263 | 370 |
| Test Name | Status |
|---|---|
testing/test_reports.py::TestReportSerialization::test_xdist_longrepr_to_str_issue_241 | Fail |
testing/test_reports.py::TestReportSerialization::test_reprentries_serialization_196 | Fail |
testing/test_reports.py::TestReportSerialization::test_deserialization_failure | Fail |
testing/test_reports.py::TestReportSerialization::test_chained_exceptions[TestReport] | Pass |
testing/test_reports.py::TestReportSerialization::test_chained_exceptions[CollectReport] | Pass |
testing/code/test_code.py::test_ne | Pass |
testing/code/test_code.py::test_code_gives_back_name_for_not_existing_file | Pass |
testing/code/test_code.py::test_code_with_class | Pass |
testing/code/test_code.py::test_code_fullsource | Pass |
testing/code/test_code.py::test_code_source | Pass |
testing/code/test_code.py::test_frame_getsourcelineno_myself | Pass |
testing/code/test_code.py::test_getstatement_empty_fullsource | Pass |
testing/code/test_code.py::test_code_from_func | Pass |
testing/code/test_code.py::test_unicode_handling | Pass |
testing/code/test_code.py::test_code_getargs | Pass |
testing/code/test_code.py::test_frame_getargs | Pass |
testing/code/test_code.py::TestExceptionInfo::test_bad_getsource | Pass |
testing/code/test_code.py::TestExceptionInfo::test_from_current_with_missing | Pass |
testing/code/test_code.py::TestTracebackEntry::test_getsource | Pass |
testing/code/test_code.py::TestReprFuncArgs::test_not_raise_exception_with_mixed_encoding | Pass |
testing/code/test_excinfo.py::test_excinfo_simple | Pass |
testing/code/test_excinfo.py::test_excinfo_from_exc_info_simple | Pass |
testing/code/test_excinfo.py::test_excinfo_getstatement | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_entries | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_entry_getsource | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_entry_getsource_in_construct | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_cut | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter_selective[<lambda>-True] | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter_selective[<lambda>-False] | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter_selective[tracebackhide2-True] | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_filter_selective[tracebackhide3-False] | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_recursion_index | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_only_specific_recursion_errors | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_no_recursion_index | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_getcrashentry | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_getcrashentry_empty | Pass |
testing/code/test_excinfo.py::test_excinfo_exconly | Pass |
testing/code/test_excinfo.py::test_excinfo_repr_str | Pass |
testing/code/test_excinfo.py::test_excinfo_for_later | Pass |
testing/code/test_excinfo.py::test_excinfo_errisinstance | Pass |
testing/code/test_excinfo.py::test_excinfo_no_sourcecode | Pass |
testing/code/test_excinfo.py::test_entrysource_Queue_example | Pass |
testing/code/test_excinfo.py::test_codepath_Queue_example | Pass |
testing/code/test_excinfo.py::test_match_succeeds | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source_excinfo | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source_not_existing | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_many_line_source_not_existing | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source_failing_fullsource | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_local | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_local_with_error | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_local_with_exception_in_class_property | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_local_truncated | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_lines | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_lines2 | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_lines_var_kw_args | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_short | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_tracebackentry_no | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_traceback_tbfilter | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_traceback_short_no_source | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_traceback_and_excinfo | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_traceback_with_invalid_cwd | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_excinfo_addouterr | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_excinfo_reprcrash | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_traceback_recursion | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_reprexcinfo_getrepr | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_reprexcinfo_unicode | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_toterminal_long | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_toterminal_long_missing_source | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_toterminal_long_incomplete_source | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_toterminal_long_filenames | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions0] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions1] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions2] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions3] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions4] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions5] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions6] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions7] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions8] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions9] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions10] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions11] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions12] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions13] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions14] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions15] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions16] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions17] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions18] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions19] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions20] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions21] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions22] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_format_excinfo[reproptions23] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_traceback_repr_style | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_chain_repr | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_repr_chain_suppression[from_none] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_repr_chain_suppression[explicit_suppress] | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_chain_repr_without_traceback[cause-The | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_chain_repr_without_traceback[context-During | Pass |
testing/code/test_excinfo.py::TestFormattedExcinfo::test_exc_chain_repr_cycle | Pass |
testing/code/test_excinfo.py::test_repr_traceback_with_unicode[None-short] | Pass |
testing/code/test_excinfo.py::test_repr_traceback_with_unicode[None-long] | Pass |
testing/code/test_excinfo.py::test_repr_traceback_with_unicode[utf8-short] | Pass |
testing/code/test_excinfo.py::test_repr_traceback_with_unicode[utf8-long] | Pass |
testing/code/test_excinfo.py::test_repr_traceback_with_unicode[utf16-short] | Pass |
testing/code/test_excinfo.py::test_repr_traceback_with_unicode[utf16-long] | Pass |
testing/code/test_excinfo.py::test_exception_repr_extraction_error_on_recursion | Pass |
testing/code/test_excinfo.py::test_no_recursion_index_on_recursion_error | Pass |
testing/code/test_excinfo.py::TestTraceback_f_g_h::test_traceback_cut_excludepath | Pass |
testing/code/test_excinfo.py::test_match_raises_error | Pass |
testing/code/test_excinfo.py::test_cwd_deleted | Pass |
testing/test_reports.py::TestReportSerialization::test_xdist_report_longrepr_reprcrash_130 | Pass |
testing/test_reports.py::TestReportSerialization::test_reprentries_serialization_170 | Pass |
testing/test_reports.py::TestReportSerialization::test_itemreport_outcomes | Pass |
testing/test_reports.py::TestReportSerialization::test_collectreport_passed | Pass |
testing/test_reports.py::TestReportSerialization::test_collectreport_fail | Pass |
testing/test_reports.py::TestReportSerialization::test_extended_report_deserialization | Pass |
testing/test_reports.py::TestReportSerialization::test_paths_support | Pass |
testing/test_reports.py::TestHooks::test_test_report | Pass |
testing/test_reports.py::TestHooks::test_collect_report | Pass |
testing/test_reports.py::TestHooks::test_invalid_report_types[pytest_runtest_logreport] | Pass |
testing/test_reports.py::TestHooks::test_invalid_report_types[pytest_collectreport] | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.