Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down
19 changes: 1 addition & 18 deletions pytest_github_actions_annotate_failures/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import contextlib
import os
import sys
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -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),
)
Expand Down
Loading