mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-02 19:32:47 +00:00
Allow AnsibleModules to be instantiated more than once in a module
Fix SELINUX monkeypatch in test_basic
This commit is contained in:
@@ -45,6 +45,7 @@ class TestAnsibleModuleExitJson(unittest.TestCase):
|
||||
self.stdout_swap_ctx = swap_stdout()
|
||||
self.fake_stream = self.stdout_swap_ctx.__enter__()
|
||||
|
||||
reload(basic)
|
||||
self.module = basic.AnsibleModule(argument_spec=dict())
|
||||
|
||||
def tearDown(self):
|
||||
@@ -125,6 +126,7 @@ class TestAnsibleModuleExitValuesRemoved(unittest.TestCase):
|
||||
params = json.dumps(params)
|
||||
|
||||
with swap_stdin_and_argv(stdin_data=params):
|
||||
reload(basic)
|
||||
with swap_stdout():
|
||||
module = basic.AnsibleModule(
|
||||
argument_spec = dict(
|
||||
@@ -146,6 +148,7 @@ class TestAnsibleModuleExitValuesRemoved(unittest.TestCase):
|
||||
params = dict(ANSIBLE_MODULE_ARGS=args, ANSIBLE_MODULE_CONSTANTS={})
|
||||
params = json.dumps(params)
|
||||
with swap_stdin_and_argv(stdin_data=params):
|
||||
reload(basic)
|
||||
with swap_stdout():
|
||||
module = basic.AnsibleModule(
|
||||
argument_spec = dict(
|
||||
|
||||
@@ -49,6 +49,7 @@ class TestAnsibleModuleSysLogSmokeTest(unittest.TestCase):
|
||||
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
|
||||
self.stdin_swap.__enter__()
|
||||
|
||||
reload(basic)
|
||||
self.am = basic.AnsibleModule(
|
||||
argument_spec = dict(),
|
||||
)
|
||||
@@ -85,6 +86,7 @@ class TestAnsibleModuleJournaldSmokeTest(unittest.TestCase):
|
||||
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
|
||||
self.stdin_swap.__enter__()
|
||||
|
||||
reload(basic)
|
||||
self.am = basic.AnsibleModule(
|
||||
argument_spec = dict(),
|
||||
)
|
||||
@@ -132,6 +134,7 @@ class TestAnsibleModuleLogSyslog(unittest.TestCase):
|
||||
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
|
||||
self.stdin_swap.__enter__()
|
||||
|
||||
reload(basic)
|
||||
self.am = basic.AnsibleModule(
|
||||
argument_spec = dict(),
|
||||
)
|
||||
@@ -192,6 +195,7 @@ class TestAnsibleModuleLogJournal(unittest.TestCase):
|
||||
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
|
||||
self.stdin_swap.__enter__()
|
||||
|
||||
reload(basic)
|
||||
self.am = basic.AnsibleModule(
|
||||
argument_spec = dict(),
|
||||
)
|
||||
|
||||
@@ -67,6 +67,7 @@ class TestAnsibleModuleRunCommand(unittest.TestCase):
|
||||
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
|
||||
self.stdin_swap.__enter__()
|
||||
|
||||
reload(basic)
|
||||
self.module = AnsibleModule(argument_spec=dict())
|
||||
self.module.fail_json = MagicMock(side_effect=SystemExit)
|
||||
|
||||
|
||||
@@ -26,6 +26,12 @@ import json
|
||||
from ansible.compat.tests import unittest
|
||||
from units.mock.procenv import swap_stdin_and_argv
|
||||
|
||||
try:
|
||||
from importlib import reload
|
||||
except:
|
||||
# Py2 has reload as a builtin
|
||||
pass
|
||||
|
||||
class TestAnsibleModuleExitJson(unittest.TestCase):
|
||||
|
||||
def test_module_utils_basic_safe_eval(self):
|
||||
@@ -34,6 +40,7 @@ class TestAnsibleModuleExitJson(unittest.TestCase):
|
||||
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={}))
|
||||
|
||||
with swap_stdin_and_argv(stdin_data=args):
|
||||
reload(basic)
|
||||
am = basic.AnsibleModule(
|
||||
argument_spec=dict(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user