File: test_traceback.py

package info (click to toggle)
ansible-core 2.20.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,760 kB
  • sloc: python: 175,447; cs: 4,929; sh: 4,732; xml: 34; makefile: 21
file content (31 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations

import pytest
import pytest_mock

from ansible.module_utils._internal import _traceback


@pytest.mark.parametrize("patched_parsed_args, event, expected", (
    (dict(_ansible_tracebacks_for=["error", "warning"]), _traceback.TracebackEvent.ERROR, True),  # included value
    (dict(_ansible_tracebacks_for=["error", "warning"]), _traceback.TracebackEvent.WARNING, True),  # included value
    (dict(_ansible_tracebacks_for=["error", "warning"]), _traceback.TracebackEvent.DEPRECATED, False),  # excluded value
    ({}, _traceback.TracebackEvent.ERROR, False),  # unspecified defaults to no tracebacks
    (dict(_ansible_tracebacks_for="bogus,values"), _traceback.TracebackEvent.ERROR, True),  # parse failure defaults to always enabled
    (None, _traceback.TracebackEvent.ERROR, True),  # fetch failure defaults to always enabled
), ids=str)
def test_default_module_traceback_config(
        patched_parsed_args: dict | None,
        event: _traceback.TracebackEvent,
        expected: bool,
        mocker: pytest_mock.MockerFixture
) -> None:
    """Validate MU traceback config behavior (including unconfigured/broken config fallbacks)."""
    from ansible.module_utils import basic

    mocker.patch.object(basic, '_PARSED_MODULE_ARGS', patched_parsed_args)

    # this should just be an importlib.reload() on _traceback, but that redeclares the enum type and breaks the world
    mocker.patch.object(_traceback, '_module_tracebacks_enabled_events', None)

    assert _traceback._is_module_traceback_enabled(event=event) is expected