diff --git a/plugin_test.py b/plugin_test.py index 5231b29..d148856 100644 --- a/plugin_test.py +++ b/plugin_test.py @@ -213,6 +213,28 @@ def test_warning(): ) +def test_annotation_warning_runpath(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("PYTEST_RUN_PATH", "some_path") + result = testdir.runpytest_subprocess() + result.stderr.fnmatch_lines( + [ + "::warning file=some_path/test_annotation_warning_runpath.py,line=6::beware", + ] + ) + + def test_annotation_fail_disabled_outside_workflow(testdir: pytest.Testdir): testdir.makepyfile( """ diff --git a/pytest_github_actions_annotate_failures/plugin.py b/pytest_github_actions_annotate_failures/plugin.py index fc493eb..061f167 100644 --- a/pytest_github_actions_annotate_failures/plugin.py +++ b/pytest_github_actions_annotate_failures/plugin.py @@ -1,6 +1,5 @@ from __future__ import annotations -import contextlib import os import sys from typing import TYPE_CHECKING @@ -110,25 +109,9 @@ def pytest_warning_recorded( if os.environ.get("GITHUB_ACTIONS") != "true": return - filesystempath = warning_message.filename - workspace = os.environ.get("GITHUB_WORKSPACE") - - if workspace: - try: - rel_path = os.path.relpath(filesystempath, workspace) - except ValueError: - # os.path.relpath() will raise ValueError on Windows - # when full_path and workspace have different mount points. - rel_path = filesystempath - if not rel_path.startswith(".."): - filesystempath = rel_path - else: - with contextlib.suppress(ValueError): - filesystempath = os.path.relpath(filesystempath) - workflow_command = _build_workflow_command( "warning", - filesystempath, + compute_path(os.path.relpath(warning_message.filename)), warning_message.lineno, message=str(warning_message.message), )