33from __future__ import (absolute_import , division , print_function )
44__metaclass__ = type
55
6+ import sys
67from ansible_collections .community .sap_libs .tests .unit .compat .mock import patch , MagicMock
78from ansible_collections .community .sap_libs .tests .unit .plugins .modules .utils import AnsibleExitJson , AnsibleFailJson , ModuleTestCase , set_module_args
89
@@ -11,15 +12,18 @@ class TestSAPRfcModule(ModuleTestCase):
1112
1213 def setUp (self ):
1314 super (TestSAPRfcModule , self ).setUp ()
14- self .mock_modules = {
15- 'pyrfc' : MagicMock (),
16- 'pyrfc.Connection' : MagicMock (),
17- 'xmltodict' : MagicMock (),
18- 'xmltodict.parse' : MagicMock ()
19- }
20- patcher = patch .dict ('sys.modules' , self .mock_modules )
21- patcher .start ()
22- self .addCleanup (patcher .stop )
15+ sys .modules ['pyrfc' ] = MagicMock ()
16+ sys .modules ['pyrfc.Connection' ] = MagicMock ()
17+ sys .modules ['xmltodict' ] = MagicMock ()
18+ sys .modules ['xmltodict.parse' ] = MagicMock ()
19+
20+ def cleanup_mocks ():
21+ del sys .modules ['pyrfc' ]
22+ del sys .modules ['pyrfc.Connection' ]
23+ del sys .modules ['xmltodict' ]
24+ del sys .modules ['xmltodict.parse' ]
25+ self .addCleanup (cleanup_mocks )
26+
2327 from ansible_collections .community .sap_libs .plugins .modules import sap_task_list_execute
2428 self .module = sap_task_list_execute
2529
0 commit comments