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():
6969 )
7070
7171
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+ """
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+
7297def test_annotation_fail_disabled_outside_workflow (testdir ):
7398 testdir .makepyfile (
7499 """
Original file line number Diff line number Diff line change @@ -59,7 +59,12 @@ def pytest_runtest_makereport(item, call):
5959 # get the error message and line number from the actual error
6060 if hasattr (report .longrepr , "reprcrash" ):
6161 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
6368 elif isinstance (report .longrepr , tuple ):
6469 _ , lineno , message = report .longrepr
6570 longrepr += "\n \n " + message
You can’t perform that action at this time.
0 commit comments