Move from nose to testr.
Granted - this takes the test suite from 3 seconds to 1 second... but there are a bunch of other ways (correctness) that testr is better than nose. Removed tests/v1/utils - it was not being used anywhere. Part of blueprint grizzly-testtools. Change-Id: I54d9a0b7dc22305ec60d779d6f19025a0b5dc785
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,8 @@
|
|||||||
.coverage
|
.coverage
|
||||||
.venv
|
.venv
|
||||||
.tox
|
.tox
|
||||||
|
.testrepository
|
||||||
|
subunit.log
|
||||||
*,cover
|
*,cover
|
||||||
cover
|
cover
|
||||||
*.pyc
|
*.pyc
|
||||||
|
4
.testr.conf
Normal file
4
.testr.conf
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[DEFAULT]
|
||||||
|
test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 ${PYTHON:-python} -m subunit.run discover -t ./ ./tests $LISTOPT $IDOPTION
|
||||||
|
test_id_option=--load-list $IDFILE
|
||||||
|
test_list_option=--list
|
63
run_tests.sh
63
run_tests.sh
@@ -9,7 +9,6 @@ function usage {
|
|||||||
echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
|
echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
|
||||||
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
|
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
|
||||||
echo " -s, --no-site-packages Isolate the virtualenv from the global Python environment"
|
echo " -s, --no-site-packages Isolate the virtualenv from the global Python environment"
|
||||||
echo " -x, --stop Stop running tests after the first error or failure."
|
|
||||||
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
|
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
|
||||||
echo " -p, --pep8 Just run pep8"
|
echo " -p, --pep8 Just run pep8"
|
||||||
echo " -P, --no-pep8 Don't run pep8"
|
echo " -P, --no-pep8 Don't run pep8"
|
||||||
@@ -33,8 +32,8 @@ function process_option {
|
|||||||
-p|--pep8) just_pep8=1;;
|
-p|--pep8) just_pep8=1;;
|
||||||
-P|--no-pep8) no_pep8=1;;
|
-P|--no-pep8) no_pep8=1;;
|
||||||
-c|--coverage) coverage=1;;
|
-c|--coverage) coverage=1;;
|
||||||
-*) noseopts="$noseopts $1";;
|
-*) testropts="$testropts $1";;
|
||||||
*) noseargs="$noseargs $1"
|
*) testrargs="$testrargs $1"
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,36 +44,62 @@ never_venv=0
|
|||||||
force=0
|
force=0
|
||||||
no_site_packages=0
|
no_site_packages=0
|
||||||
installvenvopts=
|
installvenvopts=
|
||||||
noseargs=
|
testrargs=
|
||||||
noseopts=
|
testropts=
|
||||||
wrapper=""
|
wrapper=""
|
||||||
just_pep8=0
|
just_pep8=0
|
||||||
no_pep8=0
|
no_pep8=0
|
||||||
coverage=0
|
coverage=0
|
||||||
|
|
||||||
|
LANG=en_US.UTF-8
|
||||||
|
LANGUAGE=en_US:en
|
||||||
|
LC_ALL=C
|
||||||
|
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
process_option $arg
|
process_option $arg
|
||||||
done
|
done
|
||||||
|
|
||||||
# If enabled, tell nose to collect coverage data
|
|
||||||
if [ $coverage -eq 1 ]; then
|
|
||||||
noseopts="$noseopts --with-coverage --cover-package=cinderclient"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $no_site_packages -eq 1 ]; then
|
if [ $no_site_packages -eq 1 ]; then
|
||||||
installvenvopts="--no-site-packages"
|
installvenvopts="--no-site-packages"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
function init_testr {
|
||||||
|
if [ ! -d .testrepository ]; then
|
||||||
|
${wrapper} testr init
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function run_tests {
|
function run_tests {
|
||||||
# Cleanup *.pyc
|
# Cleanup *pyc
|
||||||
${wrapper} find . -type f -name "*.pyc" -delete
|
${wrapper} find . -type f -name "*.pyc" -delete
|
||||||
|
|
||||||
|
if [ $coverage -eq 1 ]; then
|
||||||
|
# Do not test test_coverage_ext when gathering coverage.
|
||||||
|
if [ "x$testrargs" = "x" ]; then
|
||||||
|
testrargs="^(?!.*test_coverage_ext).*$"
|
||||||
|
fi
|
||||||
|
export PYTHON="${wrapper} coverage run --source cinderclient --parallel-mode"
|
||||||
|
fi
|
||||||
# Just run the test suites in current environment
|
# Just run the test suites in current environment
|
||||||
${wrapper} $NOSETESTS
|
set +e
|
||||||
# If we get some short import error right away, print the error log directly
|
TESTRTESTS="$TESTRTESTS $testrargs"
|
||||||
|
echo "Running \`${wrapper} $TESTRTESTS\`"
|
||||||
|
${wrapper} $TESTRTESTS
|
||||||
RESULT=$?
|
RESULT=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
copy_subunit_log
|
||||||
|
|
||||||
return $RESULT
|
return $RESULT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function copy_subunit_log {
|
||||||
|
LOGNAME=`cat .testrepository/next-stream`
|
||||||
|
LOGNAME=$(($LOGNAME - 1))
|
||||||
|
LOGNAME=".testrepository/${LOGNAME}"
|
||||||
|
cp $LOGNAME subunit.log
|
||||||
|
}
|
||||||
|
|
||||||
function run_pep8 {
|
function run_pep8 {
|
||||||
echo "Running pep8 ..."
|
echo "Running pep8 ..."
|
||||||
srcfiles="cinderclient tests"
|
srcfiles="cinderclient tests"
|
||||||
@@ -98,7 +123,7 @@ function run_pep8 {
|
|||||||
${wrapper} pep8 ${pep8_opts} ${srcfiles}
|
${wrapper} pep8 ${pep8_opts} ${srcfiles}
|
||||||
}
|
}
|
||||||
|
|
||||||
NOSETESTS="nosetests $noseopts $noseargs"
|
TESTRTESTS="testr run --parallel $testropts"
|
||||||
|
|
||||||
if [ $never_venv -eq 0 ]
|
if [ $never_venv -eq 0 ]
|
||||||
then
|
then
|
||||||
@@ -136,13 +161,12 @@ if [ $just_pep8 -eq 1 ]; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
init_testr
|
||||||
run_tests
|
run_tests
|
||||||
|
|
||||||
# NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
|
# NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
|
||||||
# not when we're running tests individually. To handle this, we need to
|
# not when we're running tests individually.
|
||||||
# distinguish between options (noseopts), which begin with a '-', and
|
if [ -z "$testrargs" ]; then
|
||||||
# arguments (noseargs).
|
|
||||||
if [ -z "$noseargs" ]; then
|
|
||||||
if [ $no_pep8 -eq 0 ]; then
|
if [ $no_pep8 -eq 0 ]; then
|
||||||
run_pep8
|
run_pep8
|
||||||
fi
|
fi
|
||||||
@@ -150,5 +174,6 @@ fi
|
|||||||
|
|
||||||
if [ $coverage -eq 1 ]; then
|
if [ $coverage -eq 1 ]; then
|
||||||
echo "Generating coverage report in covhtml/"
|
echo "Generating coverage report in covhtml/"
|
||||||
${wrapper} coverage html -d covhtml -i
|
${wrapper} coverage combine
|
||||||
|
${wrapper} coverage html --include='cinderclient/*' --omit='cinderclient/openstack/common/*' -d covhtml -i
|
||||||
fi
|
fi
|
||||||
|
@@ -1,11 +1,3 @@
|
|||||||
[nosetests]
|
|
||||||
cover-package = cinderclient
|
|
||||||
cover-html = true
|
|
||||||
cover-erase = true
|
|
||||||
cover-inclusive = true
|
|
||||||
verbosity=2
|
|
||||||
detailed-errors=1
|
|
||||||
|
|
||||||
[build_sphinx]
|
[build_sphinx]
|
||||||
all_files = 1
|
all_files = 1
|
||||||
source-dir = doc/source
|
source-dir = doc/source
|
||||||
|
1
setup.py
1
setup.py
@@ -43,7 +43,6 @@ setuptools.setup(
|
|||||||
tests_require=tests_require,
|
tests_require=tests_require,
|
||||||
setup_requires=['setuptools-git>=0.4'],
|
setup_requires=['setuptools-git>=0.4'],
|
||||||
dependency_links=depend_links,
|
dependency_links=depend_links,
|
||||||
test_suite="nose.collector",
|
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Development Status :: 5 - Production/Stable",
|
"Development Status :: 5 - Production/Stable",
|
||||||
"Environment :: Console",
|
"Environment :: Console",
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import testtools
|
import os
|
||||||
|
|
||||||
|
import fixtures
|
||||||
import requests
|
import requests
|
||||||
|
import testtools
|
||||||
|
|
||||||
|
|
||||||
class TestCase(testtools.TestCase):
|
class TestCase(testtools.TestCase):
|
||||||
@@ -9,6 +11,17 @@ class TestCase(testtools.TestCase):
|
|||||||
'verify': True,
|
'verify': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestCase, self).setUp()
|
||||||
|
if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or
|
||||||
|
os.environ.get('OS_STDOUT_CAPTURE') == '1'):
|
||||||
|
stdout = self.useFixture(fixtures.StringStream('stdout')).stream
|
||||||
|
self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
|
||||||
|
if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or
|
||||||
|
os.environ.get('OS_STDERR_CAPTURE') == '1'):
|
||||||
|
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
|
||||||
|
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
|
||||||
|
|
||||||
|
|
||||||
class TestResponse(requests.Response):
|
class TestResponse(requests.Response):
|
||||||
""" Class used to wrap requests.Response and provide some
|
""" Class used to wrap requests.Response and provide some
|
||||||
|
@@ -1,29 +0,0 @@
|
|||||||
from nose.tools import ok_
|
|
||||||
|
|
||||||
|
|
||||||
def fail(msg):
|
|
||||||
raise AssertionError(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def assert_in(thing, seq, msg=None):
|
|
||||||
msg = msg or "'%s' not found in %s" % (thing, seq)
|
|
||||||
ok_(thing in seq, msg)
|
|
||||||
|
|
||||||
|
|
||||||
def assert_not_in(thing, seq, msg=None):
|
|
||||||
msg = msg or "unexpected '%s' found in %s" % (thing, seq)
|
|
||||||
ok_(thing not in seq, msg)
|
|
||||||
|
|
||||||
|
|
||||||
def assert_has_keys(dict, required=[], optional=[]):
|
|
||||||
keys = dict.keys()
|
|
||||||
for k in required:
|
|
||||||
assert_in(k, keys, "required key %s missing from %s" % (k, dict))
|
|
||||||
allowed_keys = set(required) | set(optional)
|
|
||||||
extra_keys = set(keys).difference(set(required + optional))
|
|
||||||
if extra_keys:
|
|
||||||
fail("found unexpected keys: %s" % list(extra_keys))
|
|
||||||
|
|
||||||
|
|
||||||
def assert_isinstance(thing, kls):
|
|
||||||
ok_(isinstance(thing, kls), "%s is not an instance of %s" % (thing, kls))
|
|
@@ -1,11 +1,10 @@
|
|||||||
distribute>=0.6.24
|
distribute>=0.6.24
|
||||||
|
|
||||||
|
coverage
|
||||||
|
discover
|
||||||
fixtures
|
fixtures
|
||||||
mock
|
mock
|
||||||
nose
|
|
||||||
nosehtmloutput
|
|
||||||
nosexcover
|
|
||||||
openstack.nose_plugin
|
|
||||||
pep8==1.3.3
|
pep8==1.3.3
|
||||||
sphinx>=1.1.2
|
sphinx>=1.1.2
|
||||||
|
testrepository>=0.0.13
|
||||||
testtools>=0.9.22
|
testtools>=0.9.22
|
||||||
|
29
tox.ini
29
tox.ini
@@ -3,14 +3,13 @@ envlist = py26,py27,pep8
|
|||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
setenv = VIRTUAL_ENV={envdir}
|
setenv = VIRTUAL_ENV={envdir}
|
||||||
NOSE_WITH_OPENSTACK=1
|
LANG=en_US.UTF-8
|
||||||
NOSE_OPENSTACK_COLOR=1
|
LANGUAGE=en_US:en
|
||||||
NOSE_OPENSTACK_RED=0.05
|
LC_ALL=C
|
||||||
NOSE_OPENSTACK_YELLOW=0.025
|
|
||||||
NOSE_OPENSTACK_SHOW_ELAPSED=1
|
|
||||||
deps = -r{toxinidir}/tools/pip-requires
|
deps = -r{toxinidir}/tools/pip-requires
|
||||||
-r{toxinidir}/tools/test-requires
|
-r{toxinidir}/tools/test-requires
|
||||||
commands = nosetests
|
commands = python setup.py testr --testr-args='{posargs}'
|
||||||
|
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
deps = pep8
|
deps = pep8
|
||||||
@@ -20,23 +19,7 @@ commands = pep8 --repeat --show-source cinderclient setup.py
|
|||||||
commands = {posargs}
|
commands = {posargs}
|
||||||
|
|
||||||
[testenv:cover]
|
[testenv:cover]
|
||||||
commands = nosetests --cover-erase --cover-package=cinderclient --with-xcoverage
|
commands = python setup.py testr --coverage --testr-args='{posargs}'
|
||||||
|
|
||||||
[tox:jenkins]
|
[tox:jenkins]
|
||||||
downloadcache = ~/cache/pip
|
downloadcache = ~/cache/pip
|
||||||
|
|
||||||
[testenv:jenkins26]
|
|
||||||
basepython = python2.6
|
|
||||||
setenv = NOSE_WITH_XUNIT=1
|
|
||||||
|
|
||||||
[testenv:jenkins27]
|
|
||||||
basepython = python2.7
|
|
||||||
setenv = NOSE_WITH_XUNIT=1
|
|
||||||
|
|
||||||
[testenv:jenkinscover]
|
|
||||||
setenv = NOSE_WITH_XUNIT=1
|
|
||||||
commands = nosetests --cover-erase --cover-package=cinderclient --with-xcoverage
|
|
||||||
|
|
||||||
[testenv:jenkinsvenv]
|
|
||||||
setenv = NOSE_WITH_XUNIT=1
|
|
||||||
commands = {posargs}
|
|
||||||
|
Reference in New Issue
Block a user