Merge "Move test.nested to utils.nested_contexts"
This commit is contained in:
commit
2870e7a711
10
nova/test.py
10
nova/test.py
|
@ -25,7 +25,6 @@ import eventlet # noqa
|
||||||
eventlet.monkey_patch(os=False)
|
eventlet.monkey_patch(os=False)
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
import contextlib
|
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import inspect
|
import inspect
|
||||||
|
@ -76,13 +75,8 @@ _TRUE_VALUES = ('True', 'true', '1', 'yes')
|
||||||
CELL1_NAME = 'cell1'
|
CELL1_NAME = 'cell1'
|
||||||
|
|
||||||
|
|
||||||
if six.PY2:
|
# For compatibility with the large number of tests which use test.nested
|
||||||
nested = contextlib.nested
|
nested = utils.nested_contexts
|
||||||
else:
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def nested(*contexts):
|
|
||||||
with contextlib.ExitStack() as stack:
|
|
||||||
yield [stack.enter_context(c) for c in contexts]
|
|
||||||
|
|
||||||
|
|
||||||
class SampleNetworks(fixtures.Fixture):
|
class SampleNetworks(fixtures.Fixture):
|
||||||
|
|
|
@ -1303,3 +1303,12 @@ def monkey_patch():
|
||||||
# be green. To workaround this, reload the module after calling
|
# be green. To workaround this, reload the module after calling
|
||||||
# monkey_patch()
|
# monkey_patch()
|
||||||
reload_module(importutils.import_module('oslo_context.context'))
|
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