From 1ea074730d70d6c549c7011ed2f69c518ecc6e6a Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Fri, 10 Aug 2018 10:55:52 +0200 Subject: [PATCH] Remove patching the mock lib Since [1] was fixed we don't need to manually patch the mock lib to avoid silently passing mistyped assert methods on mocks. [1] https://bugs.python.org/issue21238 Change-Id: Iecf4dcf8e648c9191bf8846428683ec81812c026 --- nova/test.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/nova/test.py b/nova/test.py index bff54624f..2d225737c 100644 --- a/nova/test.py +++ b/nova/test.py @@ -35,7 +35,6 @@ import pprint import sys import fixtures -import mock from oslo_cache import core as cache from oslo_concurrency import lockutils from oslo_config import cfg @@ -152,29 +151,6 @@ class skipIf(object): 'classes') -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_calls'] - - 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 NovaExceptionReraiseFormatError(object): real_log_exception = exception.NovaException._log_exception