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
This commit is contained in:
Victor Stinner 2015-03-23 14:37:13 +01:00
parent 0560dce82f
commit b200da826c
1 changed files with 8 additions and 3 deletions

View File

@ -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):