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/common/test_extension.py | 1 + openstackclient/tests/functional/common/test_help.py | 14 +++++++------- openstackclient/tests/functional/common/test_quota.py | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'openstackclient/tests/functional/common') diff --git a/openstackclient/tests/functional/common/test_extension.py b/openstackclient/tests/functional/common/test_extension.py index d7dc398b..e3a91fe6 100644 --- a/openstackclient/tests/functional/common/test_extension.py +++ b/openstackclient/tests/functional/common/test_extension.py @@ -25,6 +25,7 @@ class ExtensionTests(base.TestCase): @classmethod def setUpClass(cls): + super(ExtensionTests, cls).setUpClass() cls.haz_network = base.is_service_enabled('network') def test_extension_list_compute(self): diff --git a/openstackclient/tests/functional/common/test_help.py b/openstackclient/tests/functional/common/test_help.py index e31d3b86..7f274099 100644 --- a/openstackclient/tests/functional/common/test_help.py +++ b/openstackclient/tests/functional/common/test_help.py @@ -12,6 +12,8 @@ import os +import fixtures + from openstackclient.tests.functional import base @@ -76,10 +78,11 @@ class HelpTests(base.TestCase): def test_commands_help_no_auth(self): """Check help commands without auth info.""" - # Pop all auth info - auth_info = {key: os.environ.pop(key) - for key in os.environ.keys() - if key.startswith('OS_')} + # Pop all auth info. os.environ will be changed in loop, so do not + # replace os.environ.keys() to os.environ + for key in os.environ.keys(): + if key.startswith('OS_'): + self.useFixture(fixtures.EnvironmentVariable(key, None)) raw_output = self.openstack('help') self.assertIn('usage: openstack', raw_output) @@ -115,6 +118,3 @@ class HelpTests(base.TestCase): self.assertIn('List containers', raw_output) raw_output = self.openstack('container list --help') self.assertIn('List containers', raw_output) - - # Restore auth info - os.environ.update(auth_info) diff --git a/openstackclient/tests/functional/common/test_quota.py b/openstackclient/tests/functional/common/test_quota.py index 1b13e95e..76c69a4d 100644 --- a/openstackclient/tests/functional/common/test_quota.py +++ b/openstackclient/tests/functional/common/test_quota.py @@ -26,6 +26,7 @@ class QuotaTests(base.TestCase): @classmethod def setUpClass(cls): + super(QuotaTests, cls).setUpClass() cls.haz_network = base.is_service_enabled('network') cls.PROJECT_NAME =\ cls.get_openstack_configuration_value('auth.project_name') -- cgit v1.2.1