File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
pytest_github_actions_annotate_failures Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1
1
name : test
2
2
3
3
on :
4
+ workflow_dispatch :
4
5
push :
5
6
branches :
6
7
- master
Original file line number Diff line number Diff line change 1
1
pytest_plugins = 'pytester'
2
2
import pytest
3
+ import os
3
4
from packaging import version
4
5
5
6
# result.stdout.no_fnmatch_line() is added to testdir on pytest 5.3.0
@@ -73,3 +74,22 @@ def test_fail():
73
74
testdir .monkeypatch .setenv ('GITHUB_ACTIONS' , '' )
74
75
result = testdir .runpytest_subprocess ()
75
76
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]\n testpaths=..' )
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
+ ])
Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ def pytest_runtest_logreport(report):
13
13
# collect information to be annotated
14
14
filesystempath , lineno , _ = report .location
15
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
23
+
16
24
# 0-index to 1-index
17
25
lineno += 1
18
26
You can’t perform that action at this time.
0 commit comments