Debian Codegraph @

test/units/module_utils/_internal/test_traceback.py

raw
1 from __future__ import annotations
2
3 import pytest
4 import pytest_mock
5
6 from ansible.module_utils._internal import _traceback
7
8
9 @pytest.mark.parametrize("patched_parsed_args, event, expected", (
10 (dict(_ansible_tracebacks_for=["error", "warning"]), _traceback.TracebackEvent.ERROR, True), # included value
11 (dict(_ansible_tracebacks_for=["error", "warning"]), _traceback.TracebackEvent.WARNING, True), # included value
12 (dict(_ansible_tracebacks_for=["error", "warning"]), _traceback.TracebackEvent.DEPRECATED, False), # excluded value
13 ({}, _traceback.TracebackEvent.ERROR, False), # unspecified defaults to no tracebacks
14 (dict(_ansible_tracebacks_for="bogus,values"), _traceback.TracebackEvent.ERROR, True), # parse failure defaults to always enabled
15 (None, _traceback.TracebackEvent.ERROR, True), # fetch failure defaults to always enabled
16 ), ids=str)
17 def test_default_module_traceback_config(
18 patched_parsed_args: dict | None,
19 event: _traceback.TracebackEvent,
20 expected: bool,
21 mocker: pytest_mock.MockerFixture
22 ) -> None:
23 """Validate MU traceback config behavior (including unconfigured/broken config fallbacks)."""
24 from ansible.module_utils import basic
25
26 mocker.patch.object(basic, '_PARSED_MODULE_ARGS', patched_parsed_args)
27
28 # this should just be an importlib.reload() on _traceback, but that redeclares the enum type and breaks the world
29 mocker.patch.object(_traceback, '_module_tracebacks_enabled_events', None)
30
31 assert _traceback._is_module_traceback_enabled(event=event) is expected