Skip to content

Commit 288b309

Browse files
authored
Merge pull request #12 from henryiii/henryiii/abspath
Henryiii/abspath
2 parents 6dbea7d + 94ff7cc commit 288b309

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: test
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- master

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)