Debian Codegraph @

test/units/modules/conftest.py

raw
1 # Copyright (c) 2017 Ansible Project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3
4 from __future__ import annotations
5
6 import typing as t
7
8 import pytest
9
10 from ansible.module_utils.testing import patch_module_args
11
12 from ..mock.module import module_env_mocker # expose shared fixture in this part of the unit test tree
13
14 assert module_env_mocker is not None # avoid unused imports
15
16
17 @pytest.fixture
18 def set_module_args() -> t.Iterator[t.Callable[[dict[str, t.Any] | None], None]]:
19 ctx: t.ContextManager | None = None
20
21 def set_module_args(args: dict[str, t.Any] | None = None) -> None:
22 nonlocal ctx
23
24 args['_ansible_remote_tmp'] = '/tmp'
25 args['_ansible_keep_remote_files'] = False
26
27 ctx = t.cast(t.ContextManager, patch_module_args(args))
28 ctx.__enter__()
29
30 try:
31 yield set_module_args
32 finally:
33 if ctx:
34 ctx.__exit__(None, None, None)