From d21b9347183b66b8bb566414b008cc277b9e2029 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Wed, 6 Apr 2016 17:02:08 -0400 Subject: [PATCH] Remove "patch mock to raise for invalid assert calls" This looks like it's causing problems with a new mock 2.0.0 release, proposing to just remove it to keep things working. Closes-Bug: #1567079 Change-Id: I2a82eec20f8099c0651a21ac7aed1a0771ef5297 --- cinder/test.py | 23 ----------------------- cinder/tests/unit/test_test.py | 6 ------ 2 files changed, 29 deletions(-) diff --git a/cinder/test.py b/cinder/test.py index 5e30a53faf2..5ef1e0d971a 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -101,29 +101,6 @@ class Database(fixtures.Fixture): os.path.join(CONF.state_path, self.sqlite_db)) -def _patch_mock_to_raise_for_invalid_assert_calls(): - def raise_for_invalid_assert_calls(wrapped): - def wrapper(_self, name): - valid_asserts = [ - 'assert_called_with', - 'assert_called_once_with', - 'assert_has_calls', - 'assert_any_call'] - - if name.startswith('assert') and name not in valid_asserts: - raise AttributeError('%s is not a valid mock assert method' - % name) - - return wrapped(_self, name) - return wrapper - mock.Mock.__getattr__ = raise_for_invalid_assert_calls( - mock.Mock.__getattr__) - -# NOTE(gibi): needs to be called only once at import time -# to patch the mock lib -_patch_mock_to_raise_for_invalid_assert_calls() - - class TestCase(testtools.TestCase): """Test case base class for all unit tests.""" diff --git a/cinder/tests/unit/test_test.py b/cinder/tests/unit/test_test.py index fb15b09d719..c2c38527be2 100644 --- a/cinder/tests/unit/test_test.py +++ b/cinder/tests/unit/test_test.py @@ -71,9 +71,3 @@ class MockAssertTestCase(test.TestCase): mock_call = mock.MagicMock(return_value=None) mock_call(1, 'foobar', a='123') mock_call.assert_called_once_with(1, 'foobar', a='123') - - def test_invalid_assert_calls(self): - mock_call = mock.MagicMock() - self.assertRaises(AttributeError, lambda: mock_call.assert_called) - self.assertRaises(AttributeError, - lambda: mock_call.assert_once_called_with)