Commit 4582aade authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[test] ensure mocking is stopped in cwctl tests

Either use a decorator or ensure that cleanup is performed.

This is so as to prevent global state modification.
parent 8673da7c2f85
......@@ -107,16 +107,17 @@ class InstanceCommandTest(unittest.TestCase):
self.CWCTL.register(_TestFailCommand)
# pretend that this instance exists
cwcfg.config_for = MagicMock(return_value=object())
def test_getting_called(self):
_TestCommand.test_instance = MagicMock(return_value=0)
patcher = patch.object(cwcfg, 'config_for', return_value=object())
patcher.start()
self.addCleanup(patcher.stop)
@patch.object(_TestCommand, 'test_instance', return_value=0)
def test_getting_called(self, test_instance):
try:
self.CWCTL.run(["test", "some_instance"])
except SystemExit as ex: # CWCTL will finish the program after that
self.assertEqual(ex.code, 0)
_TestCommand.test_instance.assert_called_with("some_instance")
test_instance.assert_called_with("some_instance")
@patch.object(cwctl, 'get_pdb')
def test_pdb_not_called(self, get_pdb):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment