[openstack-qa] Why not to use with context ?

Jay Pipes jaypipes at gmail.com
Tue Jun 11 16:22:29 UTC 2013


On 06/11/2013 12:09 PM, Attila Fazekas wrote:
> The with context are very powerful element of the python, this
> should be used wisely. I like it.
>
> One my main concern against massive with context usage is python 2.6.
> I need to use tempest with python 2.6 nowadays.
>
> In complex test case you would need to have more than 10 with.
>          with ..
>              with ..
>                  with ..
>                      with ..
>                          with ..
>                              with ..
>                                  with ..
>                                      with ..
>                                          with ..
>                                              with ..

Show me a real example of a test case that would have that many levels 
of nesting. I presume you are talking about the PoC code I put together 
that uses context managers to switch between users? If so, it's 
*switching* between users, not nested user actions. Therefore you would 
never have more than one level of nesting.

So, even if you had three different user contexts active in a single 
test case, you would still only see a single level of context manager:

def test_some_interaction(self):
   with self.do_as('net_admin') as client:
     self.assertSomething...
   with self.do_as('system_admin') as client:
     self.assertSomething...
   with self.do_as('keystone_admin') as client:
     self.assertSomething...

Best,
-jay

> http://docs.python.org/2/whatsnew/2.7.html#python-3-1-features
>
> The syntactical sugar what usable in python 2.6 is similar to the one
> used by testresources.






More information about the openstack-qa mailing list