Skip to content

Commit fe3123b

Browse files
author
Dean Troyer
committed
Move from unittest2 to testtools
Change-Id: I475a082af0660e0ee0e86ca4cd1bf0e2d711e3ed
1 parent 5418959 commit fe3123b

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

tests/test_shell.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import os
1919
import mock
2020

21+
import fixtures
2122
from openstackclient import shell as os_shell
2223
from tests import utils
2324

@@ -50,18 +51,25 @@ def make_shell():
5051

5152
class ShellTest(utils.TestCase):
5253

54+
FAKE_ENV = {
55+
'OS_AUTH_URL': DEFAULT_AUTH_URL,
56+
'OS_TENANT_ID': DEFAULT_TENANT_ID,
57+
'OS_TENANT_NAME': DEFAULT_TENANT_NAME,
58+
'OS_USERNAME': DEFAULT_USERNAME,
59+
'OS_PASSWORD': DEFAULT_PASSWORD,
60+
'OS_REGION_NAME': DEFAULT_REGION_NAME,
61+
}
62+
5363
def setUp(self):
5464
""" Patch os.environ to avoid required auth info"""
55-
global _old_env
56-
fake_env = {
57-
'OS_AUTH_URL': DEFAULT_AUTH_URL,
58-
'OS_TENANT_ID': DEFAULT_TENANT_ID,
59-
'OS_TENANT_NAME': DEFAULT_TENANT_NAME,
60-
'OS_USERNAME': DEFAULT_USERNAME,
61-
'OS_PASSWORD': DEFAULT_PASSWORD,
62-
'OS_REGION_NAME': DEFAULT_REGION_NAME,
63-
}
64-
_old_env, os.environ = os.environ, fake_env.copy()
65+
super(ShellTest, self).setUp()
66+
for var in self.FAKE_ENV:
67+
self.useFixture(
68+
fixtures.EnvironmentVariable(
69+
var,
70+
self.FAKE_ENV[var]
71+
)
72+
)
6573

6674
# Make a fake shell object, a helping wrapper to call it, and a quick
6775
# way of asserting that certain API calls were made.
@@ -77,10 +85,9 @@ def setUp(self):
7785
self.cmd_save = self.cmd_patch.start()
7886

7987
def tearDown(self):
80-
global _old_env
81-
os.environ = _old_env
8288
#self.auth_patch.stop()
8389
self.cmd_patch.stop()
90+
super(ShellTest, self).tearDown()
8491

8592
def test_shell_args(self):
8693
sh = make_shell()

tests/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import time
44

55
import mox
6-
import unittest2
6+
import testtools
77

88

9-
class TestCase(unittest2.TestCase):
9+
class TestCase(testtools.TestCase):
1010

1111
def setUp(self):
1212
super(TestCase, self).setUp()
@@ -16,6 +16,6 @@ def setUp(self):
1616

1717
def tearDown(self):
1818
time.time = self._original_time
19-
super(TestCase, self).tearDown()
2019
self.mox.UnsetStubs()
2120
self.mox.VerifyAll()
21+
super(TestCase, self).tearDown()

tools/test-requires

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
distribute>=0.6.24
22

33
coverage
4+
fixtures
45
mock
56
mox
67
nose
78
nose-exclude
9+
nosehtmloutput
810
nosexcover
911
openstack.nose_plugin
10-
nosehtmloutput
1112
pep8==0.6.1
1213
sphinx>=1.1.2
13-
unittest2
14+
testtools>=0.9.22

0 commit comments

Comments
 (0)