From 56e0f93e6bd83869e359080218bb63acbf4cc9db Mon Sep 17 00:00:00 2001 From: Patrick East Date: Mon, 13 Jul 2015 13:42:46 -0700 Subject: [PATCH] =?utf8?q?Preserve=20mock=20side=5Feffect=E2=80=99s=20in?= =?utf8?q?=20test=5Fpure?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The helper method to test if exceptions are propagated or handled would unset the mock objects side_effect value when its done. This overrides the original value making the mock not behave as expected as soon as it is passed into assert_error_propagates. This changes the helper to store the original side effect and then put it back once we are done making it throw an exception. Change-Id: I71900071a1c050913b7283aa743a17c24da1a6b9 Closes-Bug: #1474130 --- cinder/tests/unit/test_pure.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/test_pure.py b/cinder/tests/unit/test_pure.py index 26783fa7e..002449306 100644 --- a/cinder/tests/unit/test_pure.py +++ b/cinder/tests/unit/test_pure.py @@ -205,11 +205,12 @@ class PureDriverTestCase(test.TestCase): """ func(*args, **kwargs) for mock_func in mocks: + original_side_effect = mock_func.side_effect mock_func.side_effect = [exception.PureDriverException( reason='reason')] self.assertRaises(exception.PureDriverException, func, *args, **kwargs) - mock_func.side_effect = None + mock_func.side_effect = original_side_effect class PureBaseVolumeDriverTestCase(PureDriverTestCase): -- 2.45.2