diff --git a/tests/test_shell.py b/tests/test_shell.py index 6410935a0..e897fdfa0 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -18,6 +18,7 @@ import os import mock +import fixtures from openstackclient import shell as os_shell from tests import utils @@ -50,18 +51,25 @@ def make_shell(): class ShellTest(utils.TestCase): + FAKE_ENV = { + 'OS_AUTH_URL': DEFAULT_AUTH_URL, + 'OS_TENANT_ID': DEFAULT_TENANT_ID, + 'OS_TENANT_NAME': DEFAULT_TENANT_NAME, + 'OS_USERNAME': DEFAULT_USERNAME, + 'OS_PASSWORD': DEFAULT_PASSWORD, + 'OS_REGION_NAME': DEFAULT_REGION_NAME, + } + def setUp(self): """ Patch os.environ to avoid required auth info""" - global _old_env - fake_env = { - 'OS_AUTH_URL': DEFAULT_AUTH_URL, - 'OS_TENANT_ID': DEFAULT_TENANT_ID, - 'OS_TENANT_NAME': DEFAULT_TENANT_NAME, - 'OS_USERNAME': DEFAULT_USERNAME, - 'OS_PASSWORD': DEFAULT_PASSWORD, - 'OS_REGION_NAME': DEFAULT_REGION_NAME, - } - _old_env, os.environ = os.environ, fake_env.copy() + super(ShellTest, self).setUp() + for var in self.FAKE_ENV: + self.useFixture( + fixtures.EnvironmentVariable( + var, + self.FAKE_ENV[var] + ) + ) # Make a fake shell object, a helping wrapper to call it, and a quick # way of asserting that certain API calls were made. @@ -77,10 +85,9 @@ class ShellTest(utils.TestCase): self.cmd_save = self.cmd_patch.start() def tearDown(self): - global _old_env - os.environ = _old_env #self.auth_patch.stop() self.cmd_patch.stop() + super(ShellTest, self).tearDown() def test_shell_args(self): sh = make_shell() diff --git a/tests/utils.py b/tests/utils.py index 3535360d2..792fe88ea 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -3,10 +3,10 @@ import time import mox -import unittest2 +import testtools -class TestCase(unittest2.TestCase): +class TestCase(testtools.TestCase): def setUp(self): super(TestCase, self).setUp() @@ -16,6 +16,6 @@ class TestCase(unittest2.TestCase): def tearDown(self): time.time = self._original_time - super(TestCase, self).tearDown() self.mox.UnsetStubs() self.mox.VerifyAll() + super(TestCase, self).tearDown() diff --git a/tools/test-requires b/tools/test-requires index 1e9012db0..40350f025 100644 --- a/tools/test-requires +++ b/tools/test-requires @@ -1,13 +1,14 @@ distribute>=0.6.24 coverage +fixtures mock mox nose nose-exclude +nosehtmloutput nosexcover openstack.nose_plugin -nosehtmloutput pep8==0.6.1 sphinx>=1.1.2 -unittest2 +testtools>=0.9.22