File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
pytest_github_actions_annotate_failures Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,31 @@ def test_fail():
69
69
)
70
70
71
71
72
+ def test_annotation_third_party_exception (testdir ):
73
+ testdir .makepyfile (
74
+ my_module = """
75
+ def fn():
76
+ raise Exception('oops')
77
+ """
78
+ )
79
+
80
+ testdir .makepyfile (
81
+ f"""
82
+ import pytest
83
+ from my_module import fn
84
+ pytest_plugins = 'pytest_github_actions_annotate_failures'
85
+
86
+ def test_fail():
87
+ fn()
88
+ """
89
+ )
90
+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
91
+ result = testdir .runpytest_subprocess ()
92
+ result .stderr .fnmatch_lines (
93
+ ["::error file=test_annotation_third_party_exception.py,line=6::test_fail*oops*" ,]
94
+ )
95
+
96
+
72
97
def test_annotation_fail_disabled_outside_workflow (testdir ):
73
98
testdir .makepyfile (
74
99
"""
Original file line number Diff line number Diff line change @@ -59,7 +59,12 @@ def pytest_runtest_makereport(item, call):
59
59
# get the error message and line number from the actual error
60
60
if hasattr (report .longrepr , "reprcrash" ):
61
61
longrepr += "\n \n " + report .longrepr .reprcrash .message
62
- lineno = report .longrepr .reprcrash .lineno
62
+ traceback_entries = report .longrepr .reprtraceback .reprentries
63
+ if len (traceback_entries ) > 1 :
64
+ # Handle third-party exceptions
65
+ lineno = traceback_entries [0 ].reprfileloc .lineno
66
+ else :
67
+ lineno = report .longrepr .reprcrash .lineno
63
68
elif isinstance (report .longrepr , tuple ):
64
69
_ , lineno , message = report .longrepr
65
70
longrepr += "\n \n " + message
You can’t perform that action at this time.
0 commit comments