-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotate warnings #68
Annotate warnings #68
Conversation
20f27ab
to
a70c269
Compare
87145ee
to
ae9b957
Compare
Yeah, I think |
Done 494dca7! |
this is ready for another review @henryiii 🙂 |
6aaf4d7
to
5d4405e
Compare
5d4405e
to
74a4dfe
Compare
74a4dfe
to
dd855a1
Compare
FYI, we need to hide our warnings to get though CI. Mostly on pytest 6. |
with contextlib.suppress(ValueError): | ||
filesystempath = os.path.relpath(filesystempath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@henryiii this lets Windows tests pass now
Rebase post #86? |
961787f
to
d8ad95e
Compare
- Refactor workflow command generation - Skip warning annotations in Pytest < 6.0.0
d8ad95e
to
0e02dd9
Compare
Rebased. In a separate PR, I'd like to add test coverage or other means of detecting dead code after we dropped support for Pytest < 6. |
That sounds good, though IMO top priority should be fixing the line calculation for pytest 7.4+. :) |
Thanks! |
I'll take a stab. |
When I attempted it last, I had this: diff --git a/pytest_github_actions_annotate_failures/plugin.py b/pytest_github_actions_annotate_failures/plugin.py
index 8cf1e62..c635c0c 100644
--- a/pytest_github_actions_annotate_failures/plugin.py
+++ b/pytest_github_actions_annotate_failures/plugin.py
@@ -7,7 +7,7 @@ from collections import OrderedDict
from typing import TYPE_CHECKING
import pytest
-from _pytest._code.code import ExceptionRepr
+from _pytest._code.code import ExceptionRepr, ExceptionChainRepr
if TYPE_CHECKING:
from _pytest.nodes import Item
@@ -23,6 +23,28 @@ if TYPE_CHECKING:
# https://github.com/pytest-dev/pytest/blob/master/src/_pytest/terminal.py
+def compute_path(filesystempath):
+ runpath = os.environ.get("PYTEST_RUN_PATH")
+ if runpath:
+ filesystempath = os.path.join(runpath, filesystempath)
+
+ # 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
+
+ return filesystempath
+
+
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item: Item, call): # noqa: ARG001
# execute all other hooks to obtain the report object
@@ -38,24 +60,6 @@ def pytest_runtest_makereport(item: Item, call): # noqa: ARG001
# collect information to be annotated
filesystempath, lineno, _ = report.location
- runpath = os.environ.get("PYTEST_RUN_PATH")
- if runpath:
- filesystempath = os.path.join(runpath, filesystempath)
-
- # 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
@@ -65,22 +69,24 @@ def pytest_runtest_makereport(item: Item, call): # noqa: ARG001
# get the error message and line number from the actual error
if isinstance(report.longrepr, ExceptionRepr):
+ tb_entries = report.longrepr.reprtraceback.reprentries
if report.longrepr.reprcrash is not None:
longrepr += "\n\n" + report.longrepr.reprcrash.message
- tb_entries = report.longrepr.reprtraceback.reprentries
- if len(tb_entries) > 1 and tb_entries[0].reprfileloc is not None:
+ if tb_entries and tb_entries[0].reprfileloc is not None:
# Handle third-party exceptions
lineno = tb_entries[0].reprfileloc.lineno
+ filesystempath = tb_entries[0].reprfileloc.path
elif report.longrepr.reprcrash is not None:
lineno = report.longrepr.reprcrash.lineno
+ filesystempath = report.longrepr.reprcrash.path
elif isinstance(report.longrepr, tuple):
- _, lineno, message = report.longrepr
+ filesystempath, lineno, message = report.longrepr
longrepr += "\n\n" + message
elif isinstance(report.longrepr, str):
longrepr += "\n\n" + report.longrepr
print(
- _error_workflow_command(filesystempath, lineno, longrepr), file=sys.stderr
+ _error_workflow_command(compute_path(filesystempath), lineno, longrepr), file=sys.stderr
) But I still had a couple of failures. Maybe that's helpful though. |
--exclude-warning-annotations
option to exclude warning annotationsCloses #45