File tree Expand file tree Collapse file tree
pytest_github_actions_annotate_failures Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -213,6 +213,28 @@ def test_warning():
213213 )
214214
215215
216+ def test_annotation_warning_runpath (testdir : pytest .Testdir ):
217+ testdir .makepyfile (
218+ """
219+ import warnings
220+ import pytest
221+ pytest_plugins = 'pytest_github_actions_annotate_failures'
222+
223+ def test_warning():
224+ warnings.warn('beware', Warning)
225+ assert 1
226+ """
227+ )
228+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
229+ testdir .monkeypatch .setenv ("PYTEST_RUN_PATH" , "some_path" )
230+ result = testdir .runpytest_subprocess ()
231+ result .stderr .fnmatch_lines (
232+ [
233+ "::warning file=some_path/test_annotation_warning_runpath.py,line=6::beware" ,
234+ ]
235+ )
236+
237+
216238def test_annotation_fail_disabled_outside_workflow (testdir : pytest .Testdir ):
217239 testdir .makepyfile (
218240 """
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3- import contextlib
43import os
54import sys
65from typing import TYPE_CHECKING
@@ -110,25 +109,9 @@ def pytest_warning_recorded(
110109 if os .environ .get ("GITHUB_ACTIONS" ) != "true" :
111110 return
112111
113- filesystempath = warning_message .filename
114- workspace = os .environ .get ("GITHUB_WORKSPACE" )
115-
116- if workspace :
117- try :
118- rel_path = os .path .relpath (filesystempath , workspace )
119- except ValueError :
120- # os.path.relpath() will raise ValueError on Windows
121- # when full_path and workspace have different mount points.
122- rel_path = filesystempath
123- if not rel_path .startswith (".." ):
124- filesystempath = rel_path
125- else :
126- with contextlib .suppress (ValueError ):
127- filesystempath = os .path .relpath (filesystempath )
128-
129112 workflow_command = _build_workflow_command (
130113 "warning" ,
131- filesystempath ,
114+ compute_path ( os . path . relpath ( warning_message . filename )) ,
132115 warning_message .lineno ,
133116 message = str (warning_message .message ),
134117 )
You can’t perform that action at this time.
0 commit comments