From f97bfa23b71503ba6c86ff4b77e76a3b60fb8b61 Mon Sep 17 00:00:00 2001 From: Sergei Petrosian Date: Thu, 18 Apr 2024 11:55:50 +0200 Subject: [PATCH] Reset self.result, run reset in the beginning of tests --- tests/unit/test_bootloader_settings.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/unit/test_bootloader_settings.py b/tests/unit/test_bootloader_settings.py index 72137c9..34af2a4 100644 --- a/tests/unit/test_bootloader_settings.py +++ b/tests/unit/test_bootloader_settings.py @@ -174,6 +174,7 @@ class InputValidator(unittest.TestCase): def reset_vars(self): self.mock_module.run_command.reset_mock() self.mock_module.fail_json.reset_mock() + self.result = dict(changed=False, actions=list()) try: del self.kernel except AttributeError: @@ -190,6 +191,7 @@ def assert_error_msg(self, err, *cmd_args): self.mock_module.fail_json.assert_called_once_with(err) def test_validate_kernels(self): + self.reset_vars() self.kernel_action, self.kernel = bootloader_settings.validate_kernels( self.mock_module, SETTINGS[0], FACTS ) @@ -251,7 +253,6 @@ def test_validate_kernels(self): self.assert_error_msg(err, *cmd_args) self.assertIsNone(self.kernel_action) self.assertIsNone(self.kernel) - self.reset_vars() self.kernel_action, self.kernel = bootloader_settings.validate_kernels( @@ -294,6 +295,7 @@ def test_validate_kernels(self): self.reset_vars() def test_add_kernel(self): + self.reset_vars() self.kernel = bootloader_settings.get_create_kernel(SETTINGS[8]["kernel"]) bootloader_settings.add_kernel( self.mock_module, self.result, SETTINGS[8]["options"], self.kernel @@ -308,11 +310,12 @@ def test_add_kernel(self): self.result["changed"], True ) self.assertEqual( - self.result["actions"][-1], expected_cmd + self.result["actions"][0], expected_cmd ) self.reset_vars() def test_rm_kernel(self): + self.reset_vars() self.kernel = bootloader_settings.get_single_kernel(SETTINGS[3]["kernel"]) self.assertEqual( self.kernel, @@ -326,7 +329,7 @@ def test_rm_kernel(self): self.result["changed"], True ) self.assertEqual( - self.result["actions"][-1], expected_cmd + self.result["actions"][0], expected_cmd ) self.reset_vars() @@ -345,6 +348,7 @@ def test_get_boot_args(self): self.assertEqual(bootloader_args, "") def test_rm_boot_args(self): + self.reset_vars() bootloader_settings.rm_boot_args( self.mock_module, self.result, INFO, "0" ) @@ -357,11 +361,12 @@ def test_rm_boot_args(self): self.result["changed"], True ) self.assertEqual( - self.result["actions"][-1], expected_cmd + self.result["actions"][0], expected_cmd ) self.reset_vars() def test_mod_boot_args(self): + self.reset_vars() args = ( "--remove-args='arg_with_str_value_absent=test_value arg_with_int_value_absent=1 arg_without_val_absent' " + "--args='arg_with_str_value=test_value arg_with_int_value=1 arg_without_val'" @@ -376,7 +381,7 @@ def test_mod_boot_args(self): self.result["changed"], True ) self.assertEqual( - self.result["actions"][-1], expected_cmd + self.result["actions"][0], expected_cmd ) self.reset_vars() @@ -389,7 +394,7 @@ def test_mod_boot_args(self): self.result["changed"], True ) self.assertEqual( - self.result["actions"][-1], expected_cmd + self.result["actions"][0], expected_cmd ) self.reset_vars() @@ -411,7 +416,7 @@ def test_mod_boot_args(self): self.result["changed"], True ) self.assertEqual( - self.result["actions"][-1], expected_cmd + self.result["actions"][0], expected_cmd ) self.reset_vars() @@ -428,7 +433,7 @@ def test_mod_boot_args(self): self.result["changed"], True ) self.assertEqual( - self.result["actions"][-1], expected_cmd + self.result["actions"][0], expected_cmd ) self.reset_vars() @@ -445,6 +450,6 @@ def test_mod_boot_args(self): self.result["changed"], True ) self.assertEqual( - self.result["actions"][-1], expected_cmd + self.result["actions"][0], expected_cmd ) self.reset_vars()