diff options
author | Roman Podoliaka <rpodolyaka@mirantis.com> | 2015-02-25 15:38:50 +0200 |
---|---|---|
committer | Roman Podoliaka <rpodolyaka@mirantis.com> | 2015-02-25 15:51:23 +0200 |
commit | 7bfdb6a704855984ae35a1c6ef063782a4f7bf1d (patch) | |
tree | a74222b41bd754393cfe97feadcb088799def260 /oslo_db/tests | |
parent | 96cabf40ba63105959c2043ea84022b9d6973161 (diff) | |
download | oslo-db-7bfdb6a704855984ae35a1c6ef063782a4f7bf1d.tar.gz |
Make DBAPI class work with mocks correctly1.5.0
Currently, DBAPI __getattr__() implementation will *always*
implicitly wrap all mocked methods of a target class/module using
wrap_db_retry(), as retry_on_* attributes will always exist and be
true for mock instances. Not only this leads to a situation, when
we would retry methods, we were not going to retry, but this also
fails with AttributeError on functools.wraps() call, breaking valid
unit tests in projects.
DBAPI is changed in a way, so that it does dict look ups instead of
fetching instance attributes to ensure mocked methods are handled
correctly and aren't wrapped when they shouldn't be wrapped.
Related issue:
http://stackoverflow.com/questions/22204660/python-mock-wrapsf-problems
Change-Id: I36550ffa88056c53a431d64e61e84fbb44bbf68d
Diffstat (limited to 'oslo_db/tests')
-rw-r--r-- | oslo_db/tests/test_api.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/oslo_db/tests/test_api.py b/oslo_db/tests/test_api.py index 18dc586..c784afe 100644 --- a/oslo_db/tests/test_api.py +++ b/oslo_db/tests/test_api.py @@ -196,3 +196,11 @@ class DBRetryRequestCase(DBAPITestCase): res = {'result': 0} self.assertRaises(ValueError, some_method, res) self.assertEqual(max_retries + 1, res['result']) + + @mock.patch.object(DBAPI, 'api_class_call1') + @mock.patch.object(api, 'wrap_db_retry') + def test_mocked_methods_are_not_wrapped(self, mocked_wrap, mocked_method): + dbapi = api.DBAPI('oslo_db.tests.test_api') + dbapi.api_class_call1() + + self.assertFalse(mocked_wrap.called) |