From b74a3f04b3b1b182a1c36fb5672e87d722fee695 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Wed, 20 Nov 2019 17:04:32 +0100 Subject: [PATCH] Fix Python 3 functional tests run Cinderlib functional tests run fine on Python 2, but when run with Python 3.6 we fail to import base_tests from test_basic and we also get a dictionary changed size during iteration error. This patch makes it possible to run functional tests on Python 3 versions. Change-Id: Ib66b29102d58ab1600e206e205a70efa17b978f4 --- cinderlib/tests/functional/base_tests.py | 3 ++- cinderlib/tests/functional/test_basic.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cinderlib/tests/functional/base_tests.py b/cinderlib/tests/functional/base_tests.py index 0fc4854..45f724d 100644 --- a/cinderlib/tests/functional/base_tests.py +++ b/cinderlib/tests/functional/base_tests.py @@ -41,7 +41,8 @@ def set_backend(func, new_name, backend_name): def test_all_backends(cls): """Decorator to run tests in a class for all available backends.""" config = BaseFunctTestCase.ensure_config_loaded() - for fname, func in cls.__dict__.items(): + # Prevent dictionary changed size during iteration on Python 3 + for fname, func in dict(vars(cls)).items(): if fname.startswith('test_'): for backend in config['backends']: bname = backend['volume_backend_name'] diff --git a/cinderlib/tests/functional/test_basic.py b/cinderlib/tests/functional/test_basic.py index e65f994..1ed6fec 100644 --- a/cinderlib/tests/functional/test_basic.py +++ b/cinderlib/tests/functional/test_basic.py @@ -15,8 +15,8 @@ import os -import base_tests import cinderlib +from cinderlib.tests.functional import base_tests class BaseFunctTestCase(base_tests.unittest2.TestCase):