From fe3123b802cae77cf14d161cf6460a3264e6e4c2 Mon Sep 17 00:00:00 2001
From: Dean Troyer <dtroyer@gmail.com>
Date: Thu, 27 Dec 2012 11:50:53 -0600
Subject: [PATCH] Move from unittest2 to testtools

Change-Id: I475a082af0660e0ee0e86ca4cd1bf0e2d711e3ed
---
 tests/test_shell.py | 31 +++++++++++++++++++------------
 tests/utils.py      |  6 +++---
 tools/test-requires |  5 +++--
 3 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/tests/test_shell.py b/tests/test_shell.py
index 6410935a0e..e897fdfa0b 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 3535360d25..792fe88ead 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 1e9012db09..40350f0256 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