Upgrade testing to use testr.

Change-Id: Ib0e73c125c908898735e60e5b435468bc2b08316
This commit is contained in:
Monty Taylor 2013-04-06 12:21:59 -04:00
parent ffbdc2acb6
commit ef46c65837
5 changed files with 36 additions and 7 deletions

3
.gitignore vendored
View File

@ -6,8 +6,9 @@ ChangeLog
*.log
.tox
.coverage
oslo_config.egg-info/
oslo.config.egg-info/
build/
doc/build/
doc/source/api/
dist/
.testrepository/

4
.testr.conf Normal file
View File

@ -0,0 +1,4 @@
[DEFAULT]
test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_TEST_TIMEOUT=60 ${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -20,11 +20,15 @@
"""Common utilities used in testing"""
import os
import fixtures
import mox
import stubout
import testtools
TRUE_VALUES = ('true', '1', 'yes')
class MoxStubout(fixtures.Fixture):
"""Deal with code around mox and stubout as a fixture."""
@ -47,4 +51,20 @@ class BaseTestCase(testtools.TestCase):
super(BaseTestCase, self).setUp()
self.stubs = self.useFixture(MoxStubout()).stubs
self.useFixture(fixtures.FakeLogger('oslo.config'))
self.useFixture(fixtures.Timeout(30, True))
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 30)
try:
test_timeout = int(test_timeout)
except ValueError:
# If timeout value is invalid, fail hard.
print("OS_TEST_TIMEOUT set to invalid value"
" defaulting to no timeout")
test_timeout = 0
if test_timeout > 0:
self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
if os.environ.get('OS_STDOUT_CAPTURE') in TRUE_VALUES:
stdout = self.useFixture(fixtures.StringStream('stdout')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
if os.environ.get('OS_STDERR_CAPTURE') in TRUE_VALUES:
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

View File

@ -1,8 +1,9 @@
discover
fixtures>=0.3.12
mox
nose
nose-exclude
testtools>=0.9.22
python-subunit
testrepository>=0.0.13
testtools>=0.9.29
# when we can require tox>= 1.4, this can go into tox.ini:
# [testenv:cover]

View File

@ -5,7 +5,7 @@ envlist = py26,py27,pep8,pylint
setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/tools/pip-requires
-r{toxinidir}/tools/test-requires
commands = nosetests --with-doctest --exclude-dir=tests/testmods {posargs}
commands = python setup.py testr --slowest --testr-args='{posargs}'
[testenv:pep8]
deps = pep8==1.3.3
@ -17,7 +17,10 @@ commands = python ./tools/lint.py ./oslo
python ./tools/lint.py ./tests
[testenv:cover]
setenv = NOSE_WITH_COVERAGE=1
setenv = VIRTUAL_ENV={envdir}
commands =
python setup.py testr --coverage
[testenv:venv]
commands = {posargs}