Skip to content

Commit 94ff7cc

Browse files
committed
fix: use github repo root for relpath if possible
1 parent 485e1b7 commit 94ff7cc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

plugin_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def test_fail():
8686
'''
8787
)
8888
testdir.monkeypatch.setenv('GITHUB_ACTIONS', 'true')
89+
testdir.monkeypatch.setenv('GITHUB_WORKSPACE', os.path.dirname(str(testdir.tmpdir)))
8990
testdir.mkdir('foo')
9091
testdir.makefile('.ini', pytest='[pytest]\ntestpaths=..')
9192
result = testdir.runpytest_subprocess('--rootdir=foo')

pytest_github_actions_annotate_failures/plugin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ def pytest_runtest_logreport(report):
1111
return
1212

1313
# collect information to be annotated
14-
filesystem_relativepath, lineno, _ = report.location
15-
filesystempath = filesystem_relativepath.replace('../', '')
14+
filesystempath, lineno, _ = report.location
15+
16+
# try to convert to absolute path in GitHub Actions
17+
workspace = os.environ.get('GITHUB_WORKSPACE')
18+
if workspace:
19+
full_path = os.path.abspath(filesystempath)
20+
rel_path = os.path.relpath(full_path, workspace)
21+
if not rel_path.startswith('..'):
22+
filesystempath = rel_path
1623

1724
# 0-index to 1-index
1825
lineno += 1

0 commit comments

Comments
 (0)