Make sure to clean up even if an exception occurs (#50620)
This commit is contained in:
parent
2dbade4adc
commit
9a520b26e3
1 changed files with 11 additions and 10 deletions
|
@ -61,17 +61,18 @@ def setup_env(filename):
|
||||||
setattr(module.AnsibleModule, '__init__', fake)
|
setattr(module.AnsibleModule, '__init__', fake)
|
||||||
setattr(module, '_load_params', _fake_load_params)
|
setattr(module, '_load_params', _fake_load_params)
|
||||||
|
|
||||||
yield fake
|
try:
|
||||||
|
yield fake
|
||||||
|
finally:
|
||||||
|
setattr(module.AnsibleModule, '__init__', _original_init)
|
||||||
|
setattr(module, '_load_params', _original_load_params)
|
||||||
|
|
||||||
setattr(module.AnsibleModule, '__init__', _original_init)
|
# Clean up imports to prevent issues with mutable data being used in modules
|
||||||
setattr(module, '_load_params', _original_load_params)
|
for k in list(sys.modules.keys()):
|
||||||
|
# It's faster if we limit to items in ansible.module_utils
|
||||||
# Clean up imports to prevent issues with mutable data being used in modules
|
# But if this causes problems later, we should remove it
|
||||||
for k in list(sys.modules.keys()):
|
if k not in pre_sys_modules and k.startswith('ansible.module_utils.'):
|
||||||
# It's faster if we limit to items in ansible.module_utils
|
del sys.modules[k]
|
||||||
# But if this causes problems later, we should remove it
|
|
||||||
if k not in pre_sys_modules and k.startswith('ansible.module_utils.'):
|
|
||||||
del sys.modules[k]
|
|
||||||
|
|
||||||
|
|
||||||
def get_argument_spec(filename):
|
def get_argument_spec(filename):
|
||||||
|
|
Loading…
Reference in a new issue