Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
On Wed, Aug 19, 2015 at 6:51 PM, Sylvain Bauza sba...@redhat.com wrote: Hi, I was writing some tests so I added a contextlib.nested to a checked TestCase [1]. Unfortunately, contextlib.nested is no longer available in Python3 and there is no clear solution on how to provide a compatible import for both python2 and python3: - either providing a python3 compatible behaviour by using contextlib.ExitStack but that class is not available in Python 2 - or provide contextlib2 for python2 (and thus adding it to the requirements) That sounds really disruptive and blocking as we are close to the FeatureFreeze. Many other users of contextlib.nested are not impacted by the job because it excludes all of them but since the test I'm changing is part of the existing validated tests, that leaves Jenkins -1'ing my change. Of course, a 3rd solution would consist of excluding my updated test from the python3 check but I can hear others yelling at that :-) Ideas appreciated. -Sylvain [1] https://review.openstack.org/#/c/199205/18/nova/tests/unit/scheduler/test_rpcapi.py,cm Mock provides a context that patches multiple things so that no nesting is needed: http://www.voidspace.org.uk/python/mock/patch.html#patch-multiple oslotest provides fixtures for mock, so you don't need a context: http://docs.openstack.org/developer/oslotest/api.html#module-oslotest.mockpatch __ Brant __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
On Sun, 23 Aug 2015 18:32:33 -0400 Davanum Srinivas dava...@gmail.com wrote: Josh, the test.nested() in Nova uses exactly that: http://git.openstack.org/cgit/openstack/nova/tree/nova/test.py#n75 -- dims Oh, discard everything I say then :) My brain must still be partially functioning due to vacation, haha. -Josh __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
On 08/25/2015 10:17 AM, Joshua Harlow wrote: Oh, discard everything I say then :) My brain must still be partially functioning due to vacation, haha. import functools def work(vacation=False): if not vacation: get_lots_done() back_from_vacation = functools.partial(work, vacation=True) There you go, Josh. There's your partial function. Best, -jay __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
On Tue, 25 Aug 2015 12:23:28 -0700 Jay Pipes jaypi...@gmail.com wrote: On 08/25/2015 10:17 AM, Joshua Harlow wrote: Oh, discard everything I say then :) My brain must still be partially functioning due to vacation, haha. import functools def work(vacation=False): if not vacation: get_lots_done() back_from_vacation = functools.partial(work, vacation=True) There you go, Josh. There's your partial function. Best, -jay I approve of this message, ha. :) __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
Le 20/08/2015 03:37, John Garbutt a écrit : On 20 August 2015 at 01:42, melanie witt melwi...@gmail.com wrote: On Aug 19, 2015, at 16:51, Sylvain Bauza sba...@redhat.com wrote: Ideas appreciated. Instead of using the nested context managers, a way I like is to decorate a nested function in the test and call it, for example: def test_thing(self): @mock.patch(...) @mock.patch(...) @mock.patch(...) def do_test(..., ..., ...): ... do_test() +1 I have always found that more readable that the context manager thing, can't really explain why. Agreed, it looks like a good approach and leave an alternative possibility for not using the test.nested stuff. -Sylvain johnthetubaguy __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
Le 23/08/2015 02:01, Feodor Tersin a écrit : From: kevin.mitch...@rackspace.com Actually, there should no longer be a need to use contextlib.nested. We've explicitly dropped Python 2.6 compatibility, which means we're expecting compatibility with Python 2.7+ only, and as of Python 2.7, the 'with' statement supports accepting multiple 'as' clauses. The contextlib.nested tool was really only necessary to work around that functionality being missing in Python 2.6, and has been deprecated as of Python 2.7 because it's no longer necessary. 'with' statement has multiple form, but it does not allow line breaks inside. It leads to ugly formatting. See https://github.com/stackforge/ec2-api/commit/f5b320edbbc8ab554dae496dcae78be6fdd25fe7#diff-bfcbc316f2eb6b39de99a921a5753aadL631 Yeah, even if the 'with' statement accepts now more than just one clause, it doesn't accept to have it in multiple lines using the () for leaving less than 80 chars for each line. -Sylvain __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
From: kevin.mitch...@rackspace.com Actually, there should no longer be a need to use contextlib.nested. We've explicitly dropped Python 2.6 compatibility, which means we're expecting compatibility with Python 2.7+ only, and as of Python 2.7, the 'with' statement supports accepting multiple 'as' clauses. The contextlib.nested tool was really only necessary to work around that functionality being missing in Python 2.6, and has been deprecated as of Python 2.7 because it's no longer necessary. 'with' statement has multiple form, but it does not allow line breaks inside. It leads to ugly formatting.See https://github.com/stackforge/ec2-api/commit/f5b320edbbc8ab554dae496dcae78be6fdd25fe7#diff-bfcbc316f2eb6b39de99a921a5753aadL631 __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
On Fri, 21 Aug 2015 10:39:34 -0500 Kevin L. Mitchell kevin.mitch...@rackspace.com wrote: On Wed, 2015-08-19 at 16:51 -0700, Sylvain Bauza wrote: I was writing some tests so I added a contextlib.nested to a checked TestCase [1]. Unfortunately, contextlib.nested is no longer available in Python3 and there is no clear solution on how to provide a compatible import for both python2 and python3: - either providing a python3 compatible behaviour by using contextlib.ExitStack but that class is not available in Python 2 - or provide contextlib2 for python2 (and thus adding it to the requirements) Actually, there should no longer be a need to use contextlib.nested. We've explicitly dropped Python 2.6 compatibility, which means we're expecting compatibility with Python 2.7+ only, and as of Python 2.7, the 'with' statement supports accepting multiple 'as' clauses. The contextlib.nested tool was really only necessary to work around that functionality being missing in Python 2.6, and has been deprecated as of Python 2.7 because it's no longer necessary. Other option: https://contextlib2.readthedocs.org/en/latest/#contextlib2.ExitStack Which is also in py3.x https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack Might be easier to read than the multiple as clauses and such, use at your own will, but it's in the global-requirements (contextlib2 that is); so use it where applicable imho :) -Josh __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
Josh, the test.nested() in Nova uses exactly that: http://git.openstack.org/cgit/openstack/nova/tree/nova/test.py#n75 -- dims On Sun, Aug 23, 2015 at 5:16 PM, Joshua Harlow harlo...@outlook.com wrote: On Fri, 21 Aug 2015 10:39:34 -0500 Kevin L. Mitchell kevin.mitch...@rackspace.com wrote: On Wed, 2015-08-19 at 16:51 -0700, Sylvain Bauza wrote: I was writing some tests so I added a contextlib.nested to a checked TestCase [1]. Unfortunately, contextlib.nested is no longer available in Python3 and there is no clear solution on how to provide a compatible import for both python2 and python3: - either providing a python3 compatible behaviour by using contextlib.ExitStack but that class is not available in Python 2 - or provide contextlib2 for python2 (and thus adding it to the requirements) Actually, there should no longer be a need to use contextlib.nested. We've explicitly dropped Python 2.6 compatibility, which means we're expecting compatibility with Python 2.7+ only, and as of Python 2.7, the 'with' statement supports accepting multiple 'as' clauses. The contextlib.nested tool was really only necessary to work around that functionality being missing in Python 2.6, and has been deprecated as of Python 2.7 because it's no longer necessary. Other option: https://contextlib2.readthedocs.org/en/latest/#contextlib2.ExitStack Which is also in py3.x https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack Might be easier to read than the multiple as clauses and such, use at your own will, but it's in the global-requirements (contextlib2 that is); so use it where applicable imho :) -Josh __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev -- Davanum Srinivas :: https://twitter.com/dims __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
On Wed, 2015-08-19 at 16:51 -0700, Sylvain Bauza wrote: I was writing some tests so I added a contextlib.nested to a checked TestCase [1]. Unfortunately, contextlib.nested is no longer available in Python3 and there is no clear solution on how to provide a compatible import for both python2 and python3: - either providing a python3 compatible behaviour by using contextlib.ExitStack but that class is not available in Python 2 - or provide contextlib2 for python2 (and thus adding it to the requirements) Actually, there should no longer be a need to use contextlib.nested. We've explicitly dropped Python 2.6 compatibility, which means we're expecting compatibility with Python 2.7+ only, and as of Python 2.7, the 'with' statement supports accepting multiple 'as' clauses. The contextlib.nested tool was really only necessary to work around that functionality being missing in Python 2.6, and has been deprecated as of Python 2.7 because it's no longer necessary. -- Kevin L. Mitchell kevin.mitch...@rackspace.com Rackspace __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
On 20 August 2015 at 01:42, melanie witt melwi...@gmail.com wrote: On Aug 19, 2015, at 16:51, Sylvain Bauza sba...@redhat.com wrote: Ideas appreciated. Instead of using the nested context managers, a way I like is to decorate a nested function in the test and call it, for example: def test_thing(self): @mock.patch(...) @mock.patch(...) @mock.patch(...) def do_test(..., ..., ...): ... do_test() +1 I have always found that more readable that the context manager thing, can't really explain why. johnthetubaguy __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
[openstack-dev] [nova] contextlib.nested and Python3 failing
Hi, I was writing some tests so I added a contextlib.nested to a checked TestCase [1]. Unfortunately, contextlib.nested is no longer available in Python3 and there is no clear solution on how to provide a compatible import for both python2 and python3: - either providing a python3 compatible behaviour by using contextlib.ExitStack but that class is not available in Python 2 - or provide contextlib2 for python2 (and thus adding it to the requirements) That sounds really disruptive and blocking as we are close to the FeatureFreeze. Many other users of contextlib.nested are not impacted by the job because it excludes all of them but since the test I'm changing is part of the existing validated tests, that leaves Jenkins -1'ing my change. Of course, a 3rd solution would consist of excluding my updated test from the python3 check but I can hear others yelling at that :-) Ideas appreciated. -Sylvain [1] https://review.openstack.org/#/c/199205/18/nova/tests/unit/scheduler/test_rpcapi.py,cm __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
haha :) -- dims On Wed, Aug 19, 2015 at 7:59 PM, Sylvain Bauza sba...@redhat.com wrote: Le 19/08/2015 16:51, Sylvain Bauza a écrit : Hi, I was writing some tests so I added a contextlib.nested to a checked TestCase [1]. Unfortunately, contextlib.nested is no longer available in Python3 and there is no clear solution on how to provide a compatible import for both python2 and python3: - either providing a python3 compatible behaviour by using contextlib.ExitStack but that class is not available in Python 2 - or provide contextlib2 for python2 (and thus adding it to the requirements) That sounds really disruptive and blocking as we are close to the FeatureFreeze. Many other users of contextlib.nested are not impacted by the job because it excludes all of them but since the test I'm changing is part of the existing validated tests, that leaves Jenkins -1'ing my change. Of course, a 3rd solution would consist of excluding my updated test from the python3 check but I can hear others yelling at that :-) Ideas appreciated. So, I just saw there is actually already a solution for that here: https://github.com/openstack/nova/blob/master/nova/test.py#L72-L78 beer_count['dims']++ Thanks, -Sylvain [1] https://review.openstack.org/#/c/199205/18/nova/tests/unit/scheduler/test_rpcapi.py,cm __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev -- Davanum Srinivas :: https://twitter.com/dims __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
Re: [openstack-dev] [nova] contextlib.nested and Python3 failing
On Aug 19, 2015, at 16:51, Sylvain Bauza sba...@redhat.com wrote: Ideas appreciated. Instead of using the nested context managers, a way I like is to decorate a nested function in the test and call it, for example: def test_thing(self): @mock.patch(...) @mock.patch(...) @mock.patch(...) def do_test(..., ..., ...): ... do_test() -melanie (irc: melwitt) signature.asc Description: Message signed with OpenPGP using GPGMail __ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev