diff --git a/nova/test.py b/nova/test.py index cffaed044..ca0adec70 100644 --- a/nova/test.py +++ b/nova/test.py @@ -63,13 +63,13 @@ logging.setup(CONF, 'nova') _TRUE_VALUES = ('True', 'true', '1', 'yes') -if six.PY3: +if six.PY2: + nested = contextlib.nested +else: @contextlib.contextmanager def nested(*contexts): with contextlib.ExitStack() as stack: yield [stack.enter_context(c) for c in contexts] -else: - nested = contextlib.nested class SampleNetworks(fixtures.Fixture): diff --git a/nova/utils.py b/nova/utils.py index 0c013af5d..0cc9fb201 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -722,12 +722,12 @@ def monkey_patch(): # If CONF.monkey_patch is not True, this function do nothing. if not CONF.monkey_patch: return - if six.PY3: + if six.PY2: + is_method = inspect.ismethod + else: def is_method(obj): # Unbound methods became regular functions on Python 3 return inspect.ismethod(obj) or inspect.isfunction(obj) - else: - is_method = inspect.ismethod # Get list of modules and decorators for module_and_decorator in CONF.monkey_patch_modules: module, decorator_name = module_and_decorator.split(':')