123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import os
- import sys
- from collections import OrderedDict
- import pytest
- pytest_plugins = ["sentry.utils.pytest"]
- sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
- def pytest_configure(config):
- import warnings
-
-
- warnings.filterwarnings("error", "", Warning, r"^(?!(|kombu|raven|sentry))")
- @pytest.hookimpl(tryfirst=True, hookwrapper=True)
- def pytest_runtest_makereport(item, call):
-
- outcome = yield
- report = outcome.get_result()
-
-
- if os.environ.get("GITHUB_ACTIONS") != "true":
- return
-
-
-
- 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:
-
- filesystempath, lineno, _ = report.location
-
- 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:
-
-
-
- rel_path = filesystempath
- if not rel_path.startswith(".."):
- filesystempath = rel_path
- if lineno is not None:
-
- lineno += 1
-
- longrepr = report.head_line or item.name
-
- try:
- longrepr += "\n\n" + report.longrepr.reprcrash.message
- lineno = report.longrepr.reprcrash.lineno
- except AttributeError:
- pass
- print(_error_workflow_command(filesystempath, lineno, longrepr))
- def _error_workflow_command(filesystempath, lineno, longrepr):
-
- details_dict = OrderedDict()
- 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")
|