Mock yaml.safe_load safely
Just monkey-patching yaml.safe_load can break later tests because it isn't automatically undone after the test completes. Using mock.patch to set the mock will handle the cleanup safely. Change-Id: I1b8905d1074f7847e51f64d53a9eaa47d063112e
This commit is contained in:
parent
25c3f06b35
commit
06f7b3a00e
|
@ -1199,8 +1199,10 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
defaults,
|
||||
self.cmd._get_default_role_counts(parsed_args))
|
||||
|
||||
@mock.patch("yaml.safe_load")
|
||||
@mock.patch("six.moves.builtins.open")
|
||||
def test_get_default_role_counts_custom_roles(self, mock_open):
|
||||
def test_get_default_role_counts_custom_roles(self, mock_open,
|
||||
mock_safe_load):
|
||||
parsed_args = mock.Mock()
|
||||
roles_data = [
|
||||
{'name': 'ControllerApi', 'CountDefault': 3},
|
||||
|
@ -1209,7 +1211,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
{'name': 'ObjectStorage', 'CountDefault': 0},
|
||||
{'name': 'BlockStorage'}
|
||||
]
|
||||
yaml.safe_load = mock.Mock(return_value=roles_data)
|
||||
mock_safe_load.return_value = roles_data
|
||||
role_counts = {
|
||||
'ControllerApiCount': 3,
|
||||
'ControllerPcmkCount': 3,
|
||||
|
|
Loading…
Reference in New Issue