From b360214cf222dd91fda214dac419789e16a79bfe Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Wed, 27 Oct 2021 14:24:00 +0200 Subject: [PATCH] Stop requiring mocking of utils.execute if ironic-lib execute is mocked Based on unit tests, this was done intentionally, but I don't see reasons for that. It makes refactoring much harder, because sometimes you need to mock both execute functions and test them separately. In the end, utils.execute should be removed. Change-Id: I5a9c694ebe626c54f219d4870eab0a592777518d --- ironic_python_agent/tests/unit/base.py | 3 +-- ironic_python_agent/tests/unit/test_base.py | 15 --------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/ironic_python_agent/tests/unit/base.py b/ironic_python_agent/tests/unit/base.py index 7d14821f1..09019e083 100644 --- a/ironic_python_agent/tests/unit/base.py +++ b/ironic_python_agent/tests/unit/base.py @@ -25,7 +25,6 @@ from oslotest import base as test_base from ironic_python_agent.extensions import base as ext_base from ironic_python_agent import hardware -from ironic_python_agent import utils CONF = cfg.CONF @@ -58,7 +57,7 @@ class IronicAgentTest(test_base.BaseTestCase): self.patch(subprocess, 'call', do_not_call) self.patch(subprocess, 'check_call', do_not_call) self.patch(subprocess, 'check_output', do_not_call) - self.patch(utils, 'execute', do_not_call) + # ironic_python_agent.utils.execute is an alias of ironic_lib one ext_base._EXT_MANAGER = None hardware._CACHED_HW_INFO = None diff --git a/ironic_python_agent/tests/unit/test_base.py b/ironic_python_agent/tests/unit/test_base.py index 37bcac3a0..3b182ca01 100644 --- a/ironic_python_agent/tests/unit/test_base.py +++ b/ironic_python_agent/tests/unit/test_base.py @@ -50,21 +50,6 @@ class BlockExecuteTestCase(ironic_agent_base.IronicAgentTest): utils.execute("echo") self.assertEqual(2, mock_exec.call_count) - @mock.patch.object(ironic_lib.utils, "execute", autospec=True) - def test_exception_raised_for_execute_parent_mocked(self, mock_exec): - # Make sure that even if we mock the parent execute function, that we - # still get an exception for a child. So in this case utils.execute() - # calls ironic_lib.utils.execute(). Make sure an exception is raised - # even though we mocked ironic_lib.utils.execute() - exc = self.assertRaises(Exception, utils.execute, "ls") # noqa - # Have to use 'noqa' as we are raising plain Exception and we will get - # H202 error in 'pep8' check. - - self.assertEqual( - "Don't call ironic_lib.utils.execute() / " - "processutils.execute() or similar functions in tests!", - "%s" % exc) - class DontBlockExecuteTestCase(ironic_agent_base.IronicAgentTest): """Ensure we can turn off blocking access to 'execute' type functions"""