@@ -38,21 +38,28 @@ def pytest_runtest_makereport(item: Item, call): # noqa: ARG001
38
38
return
39
39
40
40
if report .when == "call" and report .failed :
41
- filesystempath , lineno = _get_location_info (report )
41
+ if report .location is None :
42
+ return
43
+
44
+ filesystempath , lineno , _ = report .location
45
+
46
+ if lineno is not None :
47
+ # 0-index to 1-index
48
+ lineno += 1
49
+
42
50
longrepr , lineno = _get_error_message (item , report , lineno )
43
51
44
52
workflow_command = _build_workflow_command (
45
53
"error" ,
46
- filesystempath ,
54
+ compute_path ( filesystempath ) ,
47
55
lineno ,
48
56
message = longrepr ,
49
57
)
50
58
print (workflow_command , file = sys .stderr )
51
59
52
- def _get_location_info (report : CollectReport ) -> tuple [str , int | None ]:
53
- """Extract and process location information from the report."""
54
- filesystempath , lineno , _ = report .location
55
60
61
+ def compute_path (filesystempath : str ) -> str :
62
+ """Extract and process location information from the report."""
56
63
runpath = os .environ .get ("PYTEST_RUN_PATH" )
57
64
if runpath :
58
65
filesystempath = os .path .join (runpath , filesystempath )
@@ -70,13 +77,14 @@ def _get_location_info(report: CollectReport) -> tuple[str, int | None]:
70
77
if not rel_path .startswith (".." ):
71
78
filesystempath = rel_path
72
79
73
- if lineno is not None :
74
- # 0-index to 1-index
75
- lineno += 1
80
+ return filesystempath
76
81
77
- return filesystempath , lineno
78
82
79
- def _get_error_message (item : Item , report : CollectReport , lineno : int | None ) -> tuple [str , int | None ]:
83
+ def _get_error_message (
84
+ item : Item ,
85
+ report : CollectReport ,
86
+ lineno : int | None ,
87
+ ) -> tuple [str , int ]:
80
88
"""Extract error message and potentially updated line number from report."""
81
89
# get the name of the current failed test, with parametrize info
82
90
longrepr = report .head_line or item .name
0 commit comments