Skip to content

Commit

Permalink
ref: remove GHA error annotations (#68012)
Browse files Browse the repository at this point in the history
these are noisy and make it difficult to decipher the diff

<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored Apr 1, 2024
1 parent b503521 commit bccf5d5
Showing 1 changed file with 0 additions and 75 deletions.
75 changes: 0 additions & 75 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from collections.abc import MutableMapping

import psutil
Expand Down Expand Up @@ -32,80 +31,6 @@ def unclosed_files():
assert frozenset(psutil.Process().open_files()) == fds


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
outcome = yield
report = outcome.get_result()

# enable only in a workflow of GitHub Actions
# ref: https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
if os.environ.get("GITHUB_ACTIONS") != "true":
return

# If we have the pytest_rerunfailures plugin,
# and there are still retries to be run,
# then do not return the error
if hasattr(item, "execution_count"):
import pytest_rerunfailures

if item.execution_count <= pytest_rerunfailures.get_reruns_count(item):
return

if report.when == "call" and report.failed:
# collect information to be annotated
filesystempath, lineno, _ = report.location

# try to convert to absolute path in GitHub Actions
workspace = os.environ.get("GITHUB_WORKSPACE")
if workspace:
full_path = os.path.abspath(filesystempath)
try:
rel_path = os.path.relpath(full_path, workspace)
except ValueError:
# os.path.relpath() will raise ValueError on Windows
# when full_path and workspace have different mount points.
# https://github.com/utgwkk/pytest-github-actions-annotate-failures/issues/20
rel_path = filesystempath
if not rel_path.startswith(".."):
filesystempath = rel_path

if lineno is not None:
# 0-index to 1-index
lineno += 1

# get the name of the current failed test, with parametrize info
longrepr = report.head_line or item.name

# get the error message and line number from the actual error
try:
longrepr += "\n\n" + report.longrepr.reprcrash.message
lineno = report.longrepr.reprcrash.lineno
except AttributeError:
pass

print(_error_workflow_command(filesystempath, lineno, longrepr)) # noqa: S002


def _error_workflow_command(filesystempath, lineno, longrepr):
# Build collection of arguments. Ordering is strict for easy testing
details_dict = {"file": filesystempath}
if lineno is not None:
details_dict["line"] = lineno

details = ",".join(f"{k}={v}" for k, v in details_dict.items())

if longrepr is None:
return f"\n::error {details}"
else:
longrepr = _escape(longrepr)
return f"\n::error {details}::{longrepr}"


def _escape(s):
return s.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")


@pytest.fixture(autouse=True)
def validate_silo_mode():
# NOTE! Hybrid cloud uses many mechanisms to simulate multiple different configurations of the application
Expand Down

0 comments on commit bccf5d5

Please sign in to comment.