Skip to content

Commit 3c82f58

Browse files
authored
fix(warnings): use GITHUB_WORKSPACE instead of GITHUB_WORKFLOW (#124)
similar to the errors case, use `GITHUB_WORKSPACE` to determine the workspace. `GITHUB_WORKFLOW` is different, it is the name of the workflow, which is usually not a filename, unless the workflow is unnamed.
1 parent 67da723 commit 3c82f58

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

plugin_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,30 @@ def test_warning():
132132
assert not result.stderr.lines
133133

134134

135+
def test_annotation_warning_cwd(testdir: pytest.Testdir):
136+
testdir.makepyfile(
137+
"""
138+
import warnings
139+
import pytest
140+
pytest_plugins = 'pytest_github_actions_annotate_failures'
141+
142+
def test_warning():
143+
warnings.warn('beware', Warning)
144+
assert 1
145+
"""
146+
)
147+
testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true")
148+
testdir.monkeypatch.setenv("GITHUB_WORKSPACE", os.path.dirname(str(testdir.tmpdir)))
149+
testdir.mkdir("foo")
150+
testdir.makefile(".ini", pytest="[pytest]\ntestpaths=..")
151+
result = testdir.runpytest_subprocess("--rootdir=foo")
152+
result.stderr.fnmatch_lines(
153+
[
154+
"::warning file=test_annotation_warning_cwd0/test_annotation_warning_cwd.py,line=6::beware",
155+
]
156+
)
157+
158+
135159
def test_annotation_third_party_exception(testdir: pytest.Testdir):
136160
testdir.makepyfile(
137161
my_module="""

pytest_github_actions_annotate_failures/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def pytest_warning_recorded(
113113
return
114114

115115
filesystempath = warning_message.filename
116-
workspace = os.environ.get("GITHUB_WORKFLOW")
116+
workspace = os.environ.get("GITHUB_WORKSPACE")
117117

118118
if workspace:
119119
try:

0 commit comments

Comments
 (0)