@@ -39,25 +39,7 @@ def pytest_runtest_makereport(item: Item, call): # noqa: ARG001
39
39
40
40
if report .when == "call" and report .failed :
41
41
filesystempath , lineno = _get_location_info (report )
42
-
43
- # get the name of the current failed test, with parametrize info
44
- longrepr = report .head_line or item .name
45
-
46
- # get the error message and line number from the actual error
47
- if isinstance (report .longrepr , ExceptionRepr ):
48
- if report .longrepr .reprcrash is not None :
49
- longrepr += "\n \n " + report .longrepr .reprcrash .message
50
- tb_entries = report .longrepr .reprtraceback .reprentries
51
- if len (tb_entries ) > 1 and tb_entries [0 ].reprfileloc is not None :
52
- # Handle third-party exceptions
53
- lineno = tb_entries [0 ].reprfileloc .lineno
54
- elif report .longrepr .reprcrash is not None :
55
- lineno = report .longrepr .reprcrash .lineno
56
- elif isinstance (report .longrepr , tuple ):
57
- _ , lineno , message = report .longrepr
58
- longrepr += "\n \n " + message
59
- elif isinstance (report .longrepr , str ):
60
- longrepr += "\n \n " + report .longrepr
42
+ longrepr , lineno = _get_error_message (item , report , lineno )
61
43
62
44
workflow_command = _build_workflow_command (
63
45
"error" ,
@@ -94,6 +76,29 @@ def _get_location_info(report: CollectReport) -> tuple[str, int | None]:
94
76
95
77
return filesystempath , lineno
96
78
79
+ def _get_error_message (item : Item , report : CollectReport , lineno : int | None ) -> tuple [str , int | None ]:
80
+ """Extract error message and potentially updated line number from report."""
81
+ # get the name of the current failed test, with parametrize info
82
+ longrepr = report .head_line or item .name
83
+
84
+ # get the error message and line number from the actual error
85
+ if isinstance (report .longrepr , ExceptionRepr ):
86
+ if report .longrepr .reprcrash is not None :
87
+ longrepr += "\n \n " + report .longrepr .reprcrash .message
88
+ tb_entries = report .longrepr .reprtraceback .reprentries
89
+ if len (tb_entries ) > 1 and tb_entries [0 ].reprfileloc is not None :
90
+ # Handle third-party exceptions
91
+ lineno = tb_entries [0 ].reprfileloc .lineno
92
+ elif report .longrepr .reprcrash is not None :
93
+ lineno = report .longrepr .reprcrash .lineno
94
+ elif isinstance (report .longrepr , tuple ):
95
+ _ , lineno , message = report .longrepr
96
+ longrepr += "\n \n " + message
97
+ elif isinstance (report .longrepr , str ):
98
+ longrepr += "\n \n " + report .longrepr
99
+
100
+ return longrepr , lineno
101
+
97
102
98
103
class _AnnotateWarnings :
99
104
def pytest_warning_recorded (self , warning_message , when , nodeid , location ): # noqa: ARG002
0 commit comments