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:
Matthew Booth 2018-10-05 16:38:38 +01:00
parent 5c0235a579
commit b5af1633a7
2 changed files with 11 additions and 8 deletions

View File

@ -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):

View File

@ -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]