Skip to content

Commit dc3c0c8

Browse files
authored
Merge pull request #11 from utgwkk/repository-absolute-path
Resolve paths
2 parents 0a68199 + 288b309 commit dc3c0c8

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pytest_plugins = 'pytester'
22
import pytest
3+
import os
34
from packaging import version
45

56
# result.stdout.no_fnmatch_line() is added to testdir on pytest 5.3.0
@@ -73,3 +74,22 @@ def test_fail():
7374
testdir.monkeypatch.setenv('GITHUB_ACTIONS', '')
7475
result = testdir.runpytest_subprocess()
7576
no_fnmatch_line(result, '::error file=test_annotation_fail_disabled_outside_workflow.py')
77+
78+
def test_annotation_fail_cwd(testdir):
79+
testdir.makepyfile(
80+
'''
81+
import pytest
82+
pytest_plugins = 'pytest_github_actions_annotate_failures'
83+
84+
def test_fail():
85+
assert 0
86+
'''
87+
)
88+
testdir.monkeypatch.setenv('GITHUB_ACTIONS', 'true')
89+
testdir.monkeypatch.setenv('GITHUB_WORKSPACE', os.path.dirname(str(testdir.tmpdir)))
90+
testdir.mkdir('foo')
91+
testdir.makefile('.ini', pytest='[pytest]\ntestpaths=..')
92+
result = testdir.runpytest_subprocess('--rootdir=foo')
93+
result.stdout.fnmatch_lines([
94+
'::error file=test_annotation_fail_cwd.py,line=4::def test_fail():*',
95+
])

pytest_github_actions_annotate_failures/plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ def pytest_runtest_logreport(report):
1313
# collect information to be annotated
1414
filesystempath, lineno, _ = report.location
1515

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
23+
1624
# 0-index to 1-index
1725
lineno += 1
1826

0 commit comments

Comments
 (0)