From b17f91e8f46c160e09dc0008b4155bcfade136a0 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 22 Dec 2025 10:28:32 -0500 Subject: [PATCH] fix(warnings): use GITHUB_WORKSPACE instead of GITHUB_WORKFLOW 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. --- plugin_test.py | 24 +++++++++++++++++++ .../plugin.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/plugin_test.py b/plugin_test.py index 1b32b6c..c52315a 100644 --- a/plugin_test.py +++ b/plugin_test.py @@ -132,6 +132,30 @@ def test_warning(): assert not result.stderr.lines +def test_annotation_warning_cwd(testdir: pytest.Testdir): + testdir.makepyfile( + """ + import warnings + import pytest + pytest_plugins = 'pytest_github_actions_annotate_failures' + + def test_warning(): + warnings.warn('beware', Warning) + assert 1 + """ + ) + testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true") + testdir.monkeypatch.setenv("GITHUB_WORKSPACE", os.path.dirname(str(testdir.tmpdir))) + testdir.mkdir("foo") + testdir.makefile(".ini", pytest="[pytest]\ntestpaths=..") + result = testdir.runpytest_subprocess("--rootdir=foo") + result.stderr.fnmatch_lines( + [ + "::warning file=test_annotation_warning_cwd0/test_annotation_warning_cwd.py,line=6::beware", + ] + ) + + def test_annotation_third_party_exception(testdir: pytest.Testdir): testdir.makepyfile( my_module=""" diff --git a/pytest_github_actions_annotate_failures/plugin.py b/pytest_github_actions_annotate_failures/plugin.py index 7f2f4cf..bc18968 100644 --- a/pytest_github_actions_annotate_failures/plugin.py +++ b/pytest_github_actions_annotate_failures/plugin.py @@ -113,7 +113,7 @@ def pytest_warning_recorded( return filesystempath = warning_message.filename - workspace = os.environ.get("GITHUB_WORKFLOW") + workspace = os.environ.get("GITHUB_WORKSPACE") if workspace: try: