Skip to content

Commit 4abc8cc

Browse files
committed
Use testr to run nova unittests.
Convert nova from using nosetests to testr for its test runner. Some tests had to be modified to get them to run properly under testr. run_tests.sh has been updated to run testr instead of nosetests. Coverage is collected by running subunit.run under coverage.py when the coverage environment is selected. Note that you will need to rebuild your virtualenvs as nose is being removed from the dependency lists and is being replaced by testr. Tests will run in different processes once this test is merged so you cannot use test classes to pass information between tests. Each test should be a proper independent unit. Additionally the -x and -d flags to run_tests.sh have been removed as there are currently no decent approximations for those functions. Change-Id: I019ca098972ca749b195f59968cf21edd5ba9109
1 parent 8652d71 commit 4abc8cc

17 files changed

+106
-104
lines changed

.testr.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[DEFAULT]
2+
test_command=${PYTHON:-python} -m subunit.run discover -t ./ ./nova/tests $LISTOPT $IDOPTION
3+
test_id_option=--load-list $IDFILE
4+
test_list_option=--list

nova/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ def setUp(self):
191191
self.useFixture(fixtures.NestedTempfile())
192192
self.useFixture(fixtures.TempHomeDir())
193193

194+
if (os.environ.get('OS_STDOUT_NOCAPTURE') != 'True' and
195+
os.environ.get('OS_STDOUT_NOCAPTURE') != '1'):
196+
stdout = self.useFixture(fixtures.DetailStream('stdout')).stream
197+
self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
198+
if (os.environ.get('OS_STDERR_NOCAPTURE') != 'True' and
199+
os.environ.get('OS_STDERR_NOCAPTURE') != '1'):
200+
stderr = self.useFixture(fixtures.DetailStream('stderr')).stream
201+
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
202+
194203
self.log_fixture = self.useFixture(fixtures.FakeLogger('nova'))
195204
self.useFixture(conf_fixture.ConfFixture(CONF))
196205

nova/tests/api/ec2/test_cloud.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import string
2626
import tempfile
2727

28+
import fixtures
29+
2830
from nova.api.ec2 import cloud
2931
from nova.api.ec2 import ec2utils
3032
from nova.api.ec2 import inst_state
@@ -101,6 +103,7 @@ def setUp(self):
101103
super(CloudTestCase, self).setUp()
102104
self.flags(compute_driver='nova.virt.fake.FakeDriver',
103105
volume_api_class='nova.tests.fake_volume.API')
106+
self.useFixture(fixtures.FakeLogger('boto'))
104107

105108
def fake_show(meh, context, id):
106109
return {'id': id,

nova/tests/conductor/test_conductor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
FAKE_IMAGE_REF = 'fake-image-ref'
3737

3838

39-
class _BaseTestCase(test.TestCase):
39+
class _BaseTestCase(object):
4040
def setUp(self):
4141
super(_BaseTestCase, self).setUp()
4242
self.db = None
@@ -223,15 +223,15 @@ def fake_get_backdoor_port(self, context):
223223
self.assertEqual(port, backdoor_port)
224224

225225

226-
class ConductorTestCase(_BaseTestCase):
226+
class ConductorTestCase(_BaseTestCase, test.TestCase):
227227
"""Conductor Manager Tests"""
228228
def setUp(self):
229229
super(ConductorTestCase, self).setUp()
230230
self.conductor = conductor_manager.ConductorManager()
231231
self.stub_out_client_exceptions()
232232

233233

234-
class ConductorRPCAPITestCase(_BaseTestCase):
234+
class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase):
235235
"""Conductor RPC API Tests"""
236236
def setUp(self):
237237
super(ConductorRPCAPITestCase, self).setUp()
@@ -240,7 +240,7 @@ def setUp(self):
240240
self.conductor = conductor_rpcapi.ConductorAPI()
241241

242242

243-
class ConductorAPITestCase(_BaseTestCase):
243+
class ConductorAPITestCase(_BaseTestCase, test.TestCase):
244244
"""Conductor API Tests"""
245245
def setUp(self):
246246
super(ConductorAPITestCase, self).setUp()

nova/tests/hyperv/basetestcase.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,16 @@ def setUp(self):
4343
def tearDown(self):
4444
super(BaseTestCase, self).tearDown()
4545

46-
has_errors = len([test for (test, msgs) in self._currentResult.errors
46+
# python-subunit will wrap test results with a decorator.
47+
# Need to access the decorated member of results to get the
48+
# actual test result when using python-subunit.
49+
if hasattr(self._currentResult, 'decorated'):
50+
result = self._currentResult.decorated
51+
else:
52+
result = self._currentResult
53+
has_errors = len([test for (test, msgs) in result.errors
4754
if test.id() == self.id()]) > 0
48-
failed = len([test for (test, msgs) in self._currentResult.failures
55+
failed = len([test for (test, msgs) in result.failures
4956
if test.id() == self.id()]) > 0
5057

5158
if not has_errors and not failed:

nova/tests/image/test_s3.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import os
2222
import tempfile
2323

24+
import fixtures
25+
2426
from nova import context
2527
import nova.db.api
2628
from nova import exception
@@ -83,6 +85,7 @@ class TestS3ImageService(test.TestCase):
8385
def setUp(self):
8486
super(TestS3ImageService, self).setUp()
8587
self.context = context.RequestContext(None, None)
88+
self.useFixture(fixtures.FakeLogger('boto'))
8689

8790
# set up one fixture to test shows, should have id '1'
8891
nova.db.api.s3_image_create(self.context,

nova/tests/integrated/test_api_samples.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
from lxml import etree
2424

25+
# Import extensions to pull in osapi_compute_extension CONF option used below.
26+
from nova.api.openstack.compute import extensions
2527
from nova.cloudpipe.pipelib import CloudPipe
2628
from nova.compute import api
2729
from nova import context

nova/tests/integrated/test_extensions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# License for the specific language governing permissions and limitations
1616
# under the License.
1717

18+
# Import extensions to pull in osapi_compute_extension CONF option used below.
19+
from nova.api.openstack.compute import extensions
1820
from nova.openstack.common import cfg
1921
from nova.openstack.common.log import logging
2022
from nova.tests.integrated import integrated_helpers

nova/tests/test_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from boto.connection import HTTPResponse
3030
except ImportError:
3131
from httplib import HTTPResponse
32+
import fixtures
3233
import webob
3334

3435
from nova.api import auth
@@ -221,6 +222,7 @@ def setUp(self):
221222
self.app = auth.InjectContext(ctxt, ec2.FaultWrapper(
222223
ec2.RequestLogging(ec2.Requestify(ec2.Authorizer(ec2.Executor()
223224
), 'nova.api.ec2.cloud.CloudController'))))
225+
self.useFixture(fixtures.FakeLogger('boto'))
224226

225227
def expect_http(self, host=None, is_secure=False, api_version=None):
226228
"""Returns a new EC2 connection"""

nova/tests/test_imagebackend.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
CONF = cfg.CONF
2828

2929

30-
class _ImageTestCase(test.TestCase):
30+
class _ImageTestCase(object):
3131
INSTANCES_PATH = '/fake'
3232

3333
def mock_create_image(self, image):
@@ -111,7 +111,7 @@ def test_cache_template_exists(self):
111111
self.mox.VerifyAll()
112112

113113

114-
class RawTestCase(_ImageTestCase):
114+
class RawTestCase(_ImageTestCase, test.TestCase):
115115

116116
SIZE = 1024
117117

@@ -161,7 +161,7 @@ def test_create_image_extend(self):
161161
self.mox.VerifyAll()
162162

163163

164-
class Qcow2TestCase(_ImageTestCase):
164+
class Qcow2TestCase(_ImageTestCase, test.TestCase):
165165
SIZE = 1024 * 1024 * 1024
166166

167167
def setUp(self):
@@ -224,7 +224,7 @@ def test_create_image_with_size_template_exists(self):
224224
self.mox.VerifyAll()
225225

226226

227-
class LvmTestCase(_ImageTestCase):
227+
class LvmTestCase(_ImageTestCase, test.TestCase):
228228
VG = 'FakeVG'
229229
TEMPLATE_SIZE = 512
230230
SIZE = 1024

nova/tests/test_virt_drivers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def wrapped_func(self, *args, **kwargs):
5757
return wrapped_func
5858

5959

60-
class _FakeDriverBackendTestCase(test.TestCase):
60+
class _FakeDriverBackendTestCase(object):
6161
def _setup_fakelibvirt(self):
6262
# So that the _supports_direct_io does the test based
6363
# on the current working directory, instead of the
@@ -142,7 +142,7 @@ def tearDown(self):
142142
super(_FakeDriverBackendTestCase, self).tearDown()
143143

144144

145-
class VirtDriverLoaderTestCase(_FakeDriverBackendTestCase):
145+
class VirtDriverLoaderTestCase(_FakeDriverBackendTestCase, test.TestCase):
146146
"""Test that ComputeManager can successfully load both
147147
old style and new style drivers and end up with the correct
148148
final class"""
@@ -532,19 +532,19 @@ def test_remove_from_aggregate(self):
532532
self.connection.remove_from_aggregate(self.ctxt, 'aggregate', 'host')
533533

534534

535-
class AbstractDriverTestCase(_VirtDriverTestCase):
535+
class AbstractDriverTestCase(_VirtDriverTestCase, test.TestCase):
536536
def setUp(self):
537537
self.driver_module = "nova.virt.driver.ComputeDriver"
538538
super(AbstractDriverTestCase, self).setUp()
539539

540540

541-
class FakeConnectionTestCase(_VirtDriverTestCase):
541+
class FakeConnectionTestCase(_VirtDriverTestCase, test.TestCase):
542542
def setUp(self):
543543
self.driver_module = 'nova.virt.fake.FakeDriver'
544544
super(FakeConnectionTestCase, self).setUp()
545545

546546

547-
class LibvirtConnTestCase(_VirtDriverTestCase):
547+
class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase):
548548
def setUp(self):
549549
# Point _VirtDriverTestCase at the right module
550550
self.driver_module = 'nova.virt.libvirt.LibvirtDriver'

nova/tests/test_xenapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ def fake_safe_copy_vdi(session, sr_ref, instance, vdi_to_copy_ref):
339339
self.stubs.Set(vm_utils, '_safe_copy_vdi', fake_safe_copy_vdi)
340340

341341
def tearDown(self):
342-
super(XenAPIVMTestCase, self).tearDown()
343342
fake_image.FakeImageService_reset()
343+
super(XenAPIVMTestCase, self).tearDown()
344344

345345
def test_init_host(self):
346346
session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass',

0 commit comments

Comments
 (0)