<div dir="ltr">Josh,<div><br></div><div>the test.nested() in Nova uses exactly that:</div><div><a href="http://git.openstack.org/cgit/openstack/nova/tree/nova/test.py#n75">http://git.openstack.org/cgit/openstack/nova/tree/nova/test.py#n75</a><br></div><div><br></div><div>-- dims</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 23, 2015 at 5:16 PM, Joshua Harlow <span dir="ltr"><<a href="mailto:harlowja@outlook.com" target="_blank">harlowja@outlook.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, 21 Aug 2015 10:39:34 -0500<br>
"Kevin L. Mitchell" <<a href="mailto:kevin.mitchell@rackspace.com">kevin.mitchell@rackspace.com</a>> wrote:<br>
<br>
> On Wed, 2015-08-19 at 16:51 -0700, Sylvain Bauza wrote:<br>
> > I was writing some tests so I added a contextlib.nested to a<br>
> > checked TestCase [1]. Unfortunately, contextlib.nested is no longer<br>
> > available in Python3 and there is no clear solution on how to<br>
> > provide a compatible import for both python2 and python3:<br>
> > - either providing a python3 compatible behaviour by using<br>
> > contextlib.ExitStack but that class is not available in Python 2<br>
> > - or provide contextlib2 for python2 (and thus adding it to the<br>
> > requirements)<br>
><br>
> Actually, there should no longer be a need to use contextlib.nested.<br>
> We've explicitly dropped Python 2.6 compatibility, which means we're<br>
> expecting compatibility with Python 2.7+ only, and as of Python 2.7,<br>
> the 'with' statement supports accepting multiple 'as' clauses. The<br>
> contextlib.nested tool was really only necessary to work around that<br>
> functionality being missing in Python 2.6, and has been deprecated as<br>
> of Python 2.7 because it's no longer necessary.<br>
<br>
Other option:<br>
<br>
<a href="https://contextlib2.readthedocs.org/en/latest/#contextlib2.ExitStack" rel="noreferrer" target="_blank">https://contextlib2.readthedocs.org/en/latest/#contextlib2.ExitStack</a><br>
<br>
Which is also in py3.x<br>
<br>
<a href="https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack" rel="noreferrer" target="_blank">https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack</a><br>
<br>
Might be easier to read than the multiple as clauses and such, use at<br>
your own will, but it's in the global-requirements (contextlib2 that<br>
is); so use it where applicable imho :)<br>
<br>
-Josh<br>
<br>
__________________________________________________________________________<br>
OpenStack Development Mailing List (not for usage questions)<br>
Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" rel="noreferrer" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" rel="noreferrer" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Davanum Srinivas :: <a href="https://twitter.com/dims" target="_blank">https://twitter.com/dims</a></div>
</div>