[test] ensure mocking is stopped in cwctl tests
authorDenis Laxalde <denis.laxalde@logilab.fr>
Mon, 22 Jul 2019 11:09:15 +0200
changeset 12693 5e7212209ea6
parent 12692 8673da7c2f85
child 12694 58f132392cba
[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.
cubicweb/test/unittest_cwctl.py
--- a/cubicweb/test/unittest_cwctl.py	Tue May 21 16:47:13 2019 +0200
+++ b/cubicweb/test/unittest_cwctl.py	Mon Jul 22 11:09:15 2019 +0200
@@ -107,16 +107,17 @@
         self.CWCTL.register(_TestFailCommand)
 
         # pretend that this instance exists
-        cwcfg.config_for = MagicMock(return_value=object())
+        patcher = patch.object(cwcfg, 'config_for', return_value=object())
+        patcher.start()
+        self.addCleanup(patcher.stop)
 
-    def test_getting_called(self):
-        _TestCommand.test_instance = MagicMock(return_value=0)
-
+    @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):