Skip to content

Commit 3e337d8

Browse files
committed
Adjust set_module_args() for data tagging.
1 parent a3eff9b commit 3e337d8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tests/unit/plugins/modules/utils.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ def set_module_args(args):
2121
if '_ansible_keep_remote_files' not in args:
2222
args['_ansible_keep_remote_files'] = False
2323

24-
serialized_args = to_bytes(json.dumps({'ANSIBLE_MODULE_ARGS': args}))
25-
with patch.object(basic, '_ANSIBLE_ARGS', serialized_args):
26-
yield
24+
try:
25+
from ansible.module_utils.testing import patch_module_args
26+
except ImportError:
27+
# Before data tagging support was merged, this was the way to go:
28+
serialized_args = to_bytes(json.dumps({'ANSIBLE_MODULE_ARGS': args}))
29+
with patch.object(basic, '_ANSIBLE_ARGS', serialized_args):
30+
yield
31+
else:
32+
# With data tagging support, we have a new helper for this:
33+
with patch_module_args(args):
34+
yield
2735

2836

2937
class AnsibleExitJson(Exception):

0 commit comments

Comments
 (0)