summaryrefslogtreecommitdiff
path: root/openstackclient/tests/functional/image
diff options
context:
space:
mode:
authorRui Chen <chenrui.momo@gmail.com>2017-06-06 21:03:33 +0800
committerDean Troyer <dtroyer@gmail.com>2017-07-20 16:39:32 +0000
commitf1d32dbe9b6f5f2e47853b9969483fa841e451f4 (patch)
tree1149b1d37c63a81caa58c9f6613f0726b9ddb3b5 /openstackclient/tests/functional/image
parentac8cac4b63590e3b583faee88b6c481f2f3e9d9a (diff)
downloadpython-openstackclient-f1d32dbe9b6f5f2e47853b9969483fa841e451f4.tar.gz
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
Diffstat (limited to 'openstackclient/tests/functional/image')
-rw-r--r--openstackclient/tests/functional/image/v1/test_image.py23
-rw-r--r--openstackclient/tests/functional/image/v2/test_image.py22
2 files changed, 35 insertions, 10 deletions
diff --git a/openstackclient/tests/functional/image/v1/test_image.py b/openstackclient/tests/functional/image/v1/test_image.py
index 901f4337..fa073f99 100644
--- a/openstackclient/tests/functional/image/v1/test_image.py
+++ b/openstackclient/tests/functional/image/v1/test_image.py
@@ -11,9 +11,10 @@
# under the License.
import json
-import os
import uuid
+import fixtures
+
from openstackclient.tests.functional import base
@@ -25,8 +26,9 @@ class ImageTests(base.TestCase):
@classmethod
def setUpClass(cls):
- os.environ['OS_IMAGE_API_VERSION'] = '1'
+ super(ImageTests, cls).setUpClass()
json_output = json.loads(cls.openstack(
+ '--os-image-api-version 1 '
'image create -f json ' +
cls.NAME
))
@@ -35,10 +37,21 @@ class ImageTests(base.TestCase):
@classmethod
def tearDownClass(cls):
- cls.openstack(
- 'image delete ' +
- cls.image_id
+ try:
+ cls.openstack(
+ '--os-image-api-version 1 '
+ 'image delete ' +
+ cls.image_id
+ )
+ finally:
+ super(ImageTests, cls).tearDownClass()
+
+ def setUp(self):
+ super(ImageTests, self).setUp()
+ ver_fixture = fixtures.EnvironmentVariable(
+ 'OS_IMAGE_API_VERSION', '1'
)
+ self.useFixture(ver_fixture)
def test_image_list(self):
json_output = json.loads(self.openstack(
diff --git a/openstackclient/tests/functional/image/v2/test_image.py b/openstackclient/tests/functional/image/v2/test_image.py
index a93fa8cb..278ba5b9 100644
--- a/openstackclient/tests/functional/image/v2/test_image.py
+++ b/openstackclient/tests/functional/image/v2/test_image.py
@@ -11,9 +11,9 @@
# under the License.
import json
-import os
import uuid
+import fixtures
# from glanceclient import exc as image_exceptions
from openstackclient.tests.functional import base
@@ -27,8 +27,9 @@ class ImageTests(base.TestCase):
@classmethod
def setUpClass(cls):
- os.environ['OS_IMAGE_API_VERSION'] = '2'
+ super(ImageTests, cls).setUpClass()
json_output = json.loads(cls.openstack(
+ '--os-image-api-version 2 '
'image create -f json ' +
cls.NAME
))
@@ -37,10 +38,21 @@ class ImageTests(base.TestCase):
@classmethod
def tearDownClass(cls):
- cls.openstack(
- 'image delete ' +
- cls.image_id
+ try:
+ cls.openstack(
+ '--os-image-api-version 2 '
+ 'image delete ' +
+ cls.image_id
+ )
+ finally:
+ super(ImageTests, cls).tearDownClass()
+
+ def setUp(self):
+ super(ImageTests, self).setUp()
+ ver_fixture = fixtures.EnvironmentVariable(
+ 'OS_IMAGE_API_VERSION', '2'
)
+ self.useFixture(ver_fixture)
def test_image_list(self):
json_output = json.loads(self.openstack(