Skip to content

Commit 46ff873

Browse files
simplify and rename _get_location_info
1 parent 299c163 commit 46ff873

File tree

1 file changed

+18
-10
lines changed
  • pytest_github_actions_annotate_failures

1 file changed

+18
-10
lines changed

pytest_github_actions_annotate_failures/plugin.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,28 @@ def pytest_runtest_makereport(item: Item, call): # noqa: ARG001
3838
return
3939

4040
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+
4250
longrepr, lineno = _get_error_message(item, report, lineno)
4351

4452
workflow_command = _build_workflow_command(
4553
"error",
46-
filesystempath,
54+
compute_path(filesystempath),
4755
lineno,
4856
message=longrepr,
4957
)
5058
print(workflow_command, file=sys.stderr)
5159

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
5560

61+
def compute_path(filesystempath: str) -> str:
62+
"""Extract and process location information from the report."""
5663
runpath = os.environ.get("PYTEST_RUN_PATH")
5764
if runpath:
5865
filesystempath = os.path.join(runpath, filesystempath)
@@ -70,13 +77,14 @@ def _get_location_info(report: CollectReport) -> tuple[str, int | None]:
7077
if not rel_path.startswith(".."):
7178
filesystempath = rel_path
7279

73-
if lineno is not None:
74-
# 0-index to 1-index
75-
lineno += 1
80+
return filesystempath
7681

77-
return filesystempath, lineno
7882

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]:
8088
"""Extract error message and potentially updated line number from report."""
8189
# get the name of the current failed test, with parametrize info
8290
longrepr = report.head_line or item.name

0 commit comments

Comments
 (0)