bug: Exceptions raised in third-party modules get the wrong line reference
edgarrmondragon opened this issue · 0 comments
edgarrmondragon commented
Consider the following test
def test_annotation_third_party_exception(testdir):
testdir.makepyfile(
my_module="""
def fn():
raise Exception('oops')
"""
)
testdir.makepyfile(
f"""
import pytest
from my_module import fn
pytest_plugins = 'pytest_github_actions_annotate_failures'
def test_fail():
fn()
"""
)
testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true")
result = testdir.runpytest_subprocess()
result.stderr.fnmatch_lines(
["::error file=test_annotation_third_party_exception.py,line=6::test_fail*oops*",]
)Running this results in the following incorrect output
::error file=test_annotation_third_party_exception.py,line=2::test_fail%0A%0AException: oops
Note that the above points to line 2, but that's in the my_module file, not in the test file. The correct line number should be 6.
I have a fix for this based on the traceback chain, so I can submit a PR.