From f1d32dbe9b6f5f2e47853b9969483fa841e451f4 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Tue, 6 Jun 2017 21:03:33 +0800 Subject: Clean up the changes of os.environ in functional tests Use fixtures to restore the API version changes of os.environ in each functional tests, aims to avoid the following test cases failing in unexpected context. And make sure setUpClass/tearDownClass call super class's corresponding methods first. Change-Id: Ie248fe9d3a9e25f1b076c9f2c363200f29a83817 Closes-Bug: #1696080 --- openstackclient/tests/functional/volume/v2/common.py | 11 +++++++---- .../tests/functional/volume/v2/test_snapshot.py | 11 +++++++---- .../tests/functional/volume/v2/test_transfer_request.py | 15 +++++++++------ .../tests/functional/volume/v2/test_volume_type.py | 7 +++++-- 4 files changed, 28 insertions(+), 16 deletions(-) (limited to 'openstackclient/tests/functional/volume/v2') diff --git a/openstackclient/tests/functional/volume/v2/common.py b/openstackclient/tests/functional/volume/v2/common.py index 1d14719f..38176714 100644 --- a/openstackclient/tests/functional/volume/v2/common.py +++ b/openstackclient/tests/functional/volume/v2/common.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import os +import fixtures from openstackclient.tests.functional.volume import base @@ -18,6 +18,9 @@ from openstackclient.tests.functional.volume import base class BaseVolumeTests(base.BaseVolumeTests): """Base class for Volume functional tests. """ - @classmethod - def setUpClass(cls): - os.environ['OS_VOLUME_API_VERSION'] = '2' + def setUp(self): + super(BaseVolumeTests, self).setUp() + ver_fixture = fixtures.EnvironmentVariable( + 'OS_VOLUME_API_VERSION', '2' + ) + self.useFixture(ver_fixture) diff --git a/openstackclient/tests/functional/volume/v2/test_snapshot.py b/openstackclient/tests/functional/volume/v2/test_snapshot.py index 2fff43c8..ba6b2c28 100644 --- a/openstackclient/tests/functional/volume/v2/test_snapshot.py +++ b/openstackclient/tests/functional/volume/v2/test_snapshot.py @@ -35,10 +35,13 @@ class VolumeSnapshotTests(common.BaseVolumeTests): @classmethod def tearDownClass(cls): - cls.wait_for_status('volume', cls.VOLLY, 'available') - raw_output = cls.openstack( - 'volume delete --force ' + cls.VOLLY) - cls.assertOutput('', raw_output) + try: + cls.wait_for_status('volume', cls.VOLLY, 'available') + raw_output = cls.openstack( + 'volume delete --force ' + cls.VOLLY) + cls.assertOutput('', raw_output) + finally: + super(VolumeSnapshotTests, cls).tearDownClass() def test_volume_snapshot__delete(self): """Test create, delete multiple""" diff --git a/openstackclient/tests/functional/volume/v2/test_transfer_request.py b/openstackclient/tests/functional/volume/v2/test_transfer_request.py index e9c2236b..33495af6 100644 --- a/openstackclient/tests/functional/volume/v2/test_transfer_request.py +++ b/openstackclient/tests/functional/volume/v2/test_transfer_request.py @@ -38,12 +38,15 @@ class TransferRequestTests(common.BaseVolumeTests): @classmethod def tearDownClass(cls): - raw_output_transfer = cls.openstack( - 'volume transfer request delete ' + cls.NAME) - raw_output_volume = cls.openstack( - 'volume delete ' + cls.VOLUME_NAME) - cls.assertOutput('', raw_output_transfer) - cls.assertOutput('', raw_output_volume) + try: + raw_output_transfer = cls.openstack( + 'volume transfer request delete ' + cls.NAME) + raw_output_volume = cls.openstack( + 'volume delete ' + cls.VOLUME_NAME) + cls.assertOutput('', raw_output_transfer) + cls.assertOutput('', raw_output_volume) + finally: + super(TransferRequestTests, cls).tearDownClass() def test_volume_transfer_request_accept(self): volume_name = uuid.uuid4().hex diff --git a/openstackclient/tests/functional/volume/v2/test_volume_type.py b/openstackclient/tests/functional/volume/v2/test_volume_type.py index 11acf2f8..99630e6b 100644 --- a/openstackclient/tests/functional/volume/v2/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v2/test_volume_type.py @@ -31,8 +31,11 @@ class VolumeTypeTests(common.BaseVolumeTests): @classmethod def tearDownClass(cls): - raw_output = cls.openstack('volume type delete ' + cls.NAME) - cls.assertOutput('', raw_output) + try: + raw_output = cls.openstack('volume type delete ' + cls.NAME) + cls.assertOutput('', raw_output) + finally: + super(VolumeTypeTests, cls).tearDownClass() def test_volume_type_list(self): cmd_output = json.loads(self.openstack('volume type list -f json')) -- cgit v1.2.1