Move test.nested to utils.nested_contexts
This function is generally useful in supporting py2/3 cross-over code, and should be available to non-test code. Change-Id: I81d13418d75b46fbdb9f6d44889a207528c8d6de
This commit is contained in:
parent
5c0235a579
commit
b5af1633a7
10
nova/test.py
10
nova/test.py
|
@ -25,7 +25,6 @@ import eventlet # noqa
|
|||
eventlet.monkey_patch(os=False)
|
||||
|
||||
import abc
|
||||
import contextlib
|
||||
import copy
|
||||
import datetime
|
||||
import inspect
|
||||
|
@ -76,13 +75,8 @@ _TRUE_VALUES = ('True', 'true', '1', 'yes')
|
|||
CELL1_NAME = 'cell1'
|
||||
|
||||
|
||||
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]
|
||||
# For compatibility with the large number of tests which use test.nested
|
||||
nested = utils.nested_contexts
|
||||
|
||||
|
||||
class SampleNetworks(fixtures.Fixture):
|
||||
|
|
|
@ -1303,3 +1303,12 @@ def monkey_patch():
|
|||
# be green. To workaround this, reload the module after calling
|
||||
# monkey_patch()
|
||||
reload_module(importutils.import_module('oslo_context.context'))
|
||||
|
||||
|
||||
if six.PY2:
|
||||
nested_contexts = contextlib.nested
|
||||
else:
|
||||
@contextlib.contextmanager
|
||||
def nested_contexts(*contexts):
|
||||
with contextlib.ExitStack() as stack:
|
||||
yield [stack.enter_context(c) for c in contexts]
|
||||
|
|
Loading…
Reference in New Issue