[openstack-qa] Issue with global variable

Sean Dague sean at dague.net
Fri May 31 17:07:35 UTC 2013


So I think you are hitting a python scoping issue (though someone with 
greater python-fu than I can slap me down).

In the old patch, even though the we were setting class variables, the 
important part was that we were doing it early. The skipIf decorator 
isn't evaluating the class variable, it's actually getting the variable 
directly from it's current scope.

This is why changing the variable later isn't any good (in the second 
patch), because the decorator was already evaluated. You may be able to 
build a trickier decorator which does a late load based on the class.

	-Sean

On 05/31/2013 11:47 AM, Jérôme Gallard wrote:
> Hi all,
>
> I am working on a review: https://review.openstack.org/#/c/30760/7
> I have an issue with global variables.
>
> L123 of this file :
> https://review.openstack.org/#/c/30760/7/tempest/api/volume/admin/test_multi_backend.py
> there is a skipIf.
> The skipIf depends of the "backends_have_same_name" global variable
> (declared L30).
> "backends_have_same_name is initialized at False.
>
> During setUp, if backend1_name and backend2_name are equals,
> "backends_have_same_name" is set to True (L41).
>
> The issue is that, when backends_have_same_name is set to True (L41),
> it's not taken into account on the skipIf (L123).
>
> More details:
> In my case, the skipIf is not working properly. In my tempest.conf I set
> both backend name to the same name. Then, I run the following command:
> nosetests -sv tempest/api/volume/admin/test_multi_backend.py.
> I expect to get a "Backends configured with same name" (L124) but,
> instead of that, I get an error:
> ----
> nose.config: INFO: Ignoring files matching ['^\\.', '^_', '^setup\\.py$']
> tempest.api.volume.admin.test_multi_backend.VolumeMultiBackendTest.test_backend_name_distinction[gate]
> ... ERROR
> tempest.api.volume.admin.test_multi_backend.VolumeMultiBackendTest.test_backend_name_reporting[gate,smoke]
> ... ok
>
> ======================================================================
> ERROR:
> tempest.api.volume.admin.test_multi_backend.VolumeMultiBackendTest.test_backend_name_distinction[gate]
> ----------------------------------------------------------------------
> _StringException: Traceback (most recent call last):
>    File
> "/opt/stack/tempest/tempest/api/volume/admin/test_multi_backend.py",
> line 132, in test_backend_name_distinction
>      resp, fetched_volume = self.client.get_volume(self.volume2['id'])
> AttributeError: 'VolumeMultiBackendTest' object has no attribute 'volume2'
> ----
>
> But of course, I understand this error, because, "volume2" was never
> created (L76).
>
> May someone has an idea about why this skip is not taken into account?
>
> Thanks a lot!
>
> Regards,
> Jérôme
>
>
> _______________________________________________
> openstack-qa mailing list
> openstack-qa at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-qa
>


-- 
Sean Dague
http://dague.net



More information about the openstack-qa mailing list