ansible/test/units/_internal/test_event_formatting.py
Matt Davis cbcefc53a3
Clean up TE error handling, wrap sigalrm handler (#85232)
* Clean up TE error handling, wrap sigalrm handler

* Preserve error detail on AnsibleAction and Connection exceptions.
* Remove multiple layers of unreachable or redundant error handling.
* Wrap manual alarm signal/timeout handling into a context manager, add tests.

Co-authored-by: Matt Clay <matt@mystile.com>

* update error message check in test

* update test timeout message assertions

---------

Co-authored-by: Matt Clay <matt@mystile.com>
2025-05-30 10:45:10 -07:00

27 lines
798 B
Python

from __future__ import annotations
import traceback
from ansible._internal._errors import _error_factory
from ansible._internal._event_formatting import format_event_traceback
from units.mock.error_helper import raise_exceptions
import pytest
def test_traceback_formatting() -> None:
"""Verify our traceback formatting mimics the Python traceback formatting."""
with pytest.raises(Exception) as error:
raise_exceptions((
Exception('a'),
Exception('b'),
Exception('c'),
Exception('d'),
))
event = _error_factory.ControllerEventFactory.from_exception(error.value, True)
ansible_tb = format_event_traceback(event)
python_tb = ''.join(traceback.format_exception(error.value))
assert ansible_tb == python_tb