[PR #9838/a1781d09 backport][stable-10] Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9839)

Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9838)

Make set_module_args() a context manager, and remove copies of set_module_args().

Prepares for Data Tagging.

(cherry picked from commit a1781d09dd)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2025-03-07 07:27:55 +01:00 committed by GitHub
parent cd0ca389ed
commit 7d45b678e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
84 changed files with 4043 additions and 4302 deletions

View file

@ -5,6 +5,7 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import contextlib as _contextlib
import json
from ansible_collections.community.general.tests.unit.compat import unittest
@ -13,14 +14,16 @@ from ansible.module_utils import basic
from ansible.module_utils.common.text.converters import to_bytes
@_contextlib.contextmanager
def set_module_args(args):
if '_ansible_remote_tmp' not in args:
args['_ansible_remote_tmp'] = '/tmp'
if '_ansible_keep_remote_files' not in args:
args['_ansible_keep_remote_files'] = False
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
basic._ANSIBLE_ARGS = to_bytes(args)
serialized_args = to_bytes(json.dumps({'ANSIBLE_MODULE_ARGS': args}))
with patch.object(basic, '_ANSIBLE_ARGS', serialized_args):
yield
class AnsibleExitJson(Exception):