From b200da826c9429555ba513713a6453aa55ccde55 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 23 Mar 2015 14:37:13 +0100 Subject: [PATCH] Fix test_netutils: stop patches test_netutils monkey patches os.path.exists() and six.moves.builtins.open() using mock, but it didn't stop the patchs. A side effect is that test_excutils started to fail when executed after test_netutils. Randomly, test_excutils was executed before or after test_netutils, so test_excutils failure was random. Closes-Bug: #1433800 Change-Id: Ifbe79c52f34b4373721e9aa2e22eb86f39b60b87 --- oslo_utils/tests/test_netutils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/oslo_utils/tests/test_netutils.py b/oslo_utils/tests/test_netutils.py index 1bc4990e..406633ec 100644 --- a/oslo_utils/tests/test_netutils.py +++ b/oslo_utils/tests/test_netutils.py @@ -275,9 +275,14 @@ class TestIsIPv6Enabled(test_base.BaseTestCase): netutils._IS_IPV6_ENABLED = None reset_detection_flag() self.addCleanup(reset_detection_flag) - self.mock_exists = mock.patch("os.path.exists", - return_value=True).start() - mock_open = mock.patch("six.moves.builtins.open").start() + + patch_exists = mock.patch("os.path.exists", return_value=True) + self.addCleanup(patch_exists.stop) + self.mock_exists = patch_exists.start() + + patch_open = mock.patch("six.moves.builtins.open") + self.addCleanup(patch_open.stop) + mock_open = patch_open.start() self.mock_read = mock_open.return_value.__enter__.return_value.read def test_enabled(self):