Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace nose with testr
- add .testr.conf (in base dir and nova_tests)
- remove all references to nose
- adjust paths: A couple of tests would assume the current directory
  was ./tests/ but it is now ./
- don't run the tests in parallel as the db tests have one connection
  per test class.

nova_tests hackery:
It seems testtools/testr imports everything and I just don't see a way of
running things in tests/ and nova_tests/ seperately but in one .test.conf.
So if you want to use testr directly you will need to:
 testr run
 cd nova_tests
 testr run

part of bug 1177924
Change-Id: I41875dcf94463fa5f9c07a7840c37089226c59ad
  • Loading branch information
asalkeld committed May 18, 2013
1 parent 6693c9f commit 1a723a0
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -6,6 +6,8 @@ build
.coverage
.tox
cover
.testrepository
subunit.log
AUTHORS
ChangeLog
*.deb
Expand Down
4 changes: 4 additions & 0 deletions .testr.conf
@@ -0,0 +1,4 @@
[DEFAULT]
test_command=${PYTHON:-python} -m subunit.run discover -t ./ ./tests $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
5 changes: 3 additions & 2 deletions ceilometer/api/v1/app.py
Expand Up @@ -29,12 +29,13 @@
storage.register_opts(cfg.CONF)


def make_app(conf, enable_acl=True, attach_storage=True):
def make_app(conf, enable_acl=True, attach_storage=True,
sources_file='sources.json'):
app = flask.Flask('ceilometer.api')
app.register_blueprint(v1_blueprint.blueprint, url_prefix='/v1')

try:
with open("sources.json", "r") as f:
with open(sources_file, "r") as f:
sources = jsonutils.load(f)
except IOError:
sources = {}
Expand Down
12 changes: 6 additions & 6 deletions ceilometer/tests/api.py
Expand Up @@ -41,9 +41,13 @@ class TestBase(db_test_base.TestBase):
def setUp(self):
super(TestBase, self).setUp()
cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME)
cfg.CONF.set_override("policy_file",
self.path_get('tests/policy.json'))
sources_file = self.path_get('tests/sources.json')
self.app = v1_app.make_app(cfg.CONF,
enable_acl=False,
attach_storage=False)
attach_storage=False,
sources_file=sources_file)
self.app.register_blueprint(v1_blueprint.blueprint)
self.test_app = self.app.test_client()

Expand Down Expand Up @@ -86,11 +90,7 @@ def setUp(self):

def _make_app(self, enable_acl=False):
# Determine where we are so we can set up paths in the config
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..',
'..',
)
)
root_dir = self.path_get()

self.config = {

Expand Down
13 changes: 12 additions & 1 deletion ceilometer/tests/base.py
Expand Up @@ -42,9 +42,20 @@ def setUp(self):
# the system.
cfg.CONF.set_override(
'pipeline_cfg_file',
'../etc/ceilometer/pipeline.yaml',
self.path_get('etc/ceilometer/pipeline.yaml'),
)

def path_get(self, project_file=None):
root = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..',
'..',
)
)
if project_file:
return os.path.join(root, project_file)
else:
return root

def temp_config_file_path(self, name='ceilometer.conf'):
return os.path.join(self.tempdir.path, name)

Expand Down
4 changes: 4 additions & 0 deletions nova_tests/.testr.conf
@@ -0,0 +1,4 @@
[DEFAULT]
test_command=${PYTHON:-python} -m subunit.run discover -t ./nova_tests ./nova_tests $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
9 changes: 0 additions & 9 deletions setup.cfg
Expand Up @@ -85,15 +85,6 @@ ceilometer.publisher =
meter_publisher = ceilometer.publisher.meter:MeterPublisher
meter = ceilometer.publisher.meter:MeterPublisher

[nosetests]
cover-package = ceilometer
cover-html = true
cover-erase = true
cover-inclusive = true
verbosity=2
detailed-errors=1
where=tests

[build_sphinx]
all_files = 1
build-dir = doc/build
Expand Down
5 changes: 3 additions & 2 deletions tests/api/v2/test_app.py
Expand Up @@ -40,15 +40,16 @@ def test_keystone_middleware_conf(self):
group=acl.OPT_GROUP_NAME)
cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME)
cfg.CONF.set_override("pipeline_cfg_file",
"../etc/ceilometer/pipeline.yaml")
self.path_get("etc/ceilometer/pipeline.yaml"))
api_app = app.setup_app()
self.assertEqual(api_app.auth_protocol, 'foottp')

def test_keystone_middleware_parse_conffile(self):
tmpfile = self.temp_config_file_path()
with open(tmpfile, "w") as f:
f.write("[DEFAULT]\n")
f.write("pipeline_cfg_file = ../etc/ceilometer/pipeline.yaml\n")
f.write("pipeline_cfg_file = %s\n" %
self.path_get("etc/ceilometer/pipeline.yaml"))
f.write("[%s]\n" % acl.OPT_GROUP_NAME)
f.write("auth_protocol = barttp\n")
f.write("auth_version = v2.0\n")
Expand Down
15 changes: 10 additions & 5 deletions tests/test_bin.py
Expand Up @@ -36,7 +36,7 @@ def setUp(self):
tmp.write("database_connection=log://localhost\n")

def test_dbsync_run(self):
subp = subprocess.Popen(["../bin/ceilometer-dbsync",
subp = subprocess.Popen([self.path_get('bin/ceilometer-dbsync'),
"--config-file=%s" % self.tempfile])
self.assertEqual(subp.wait(), 0)

Expand All @@ -45,15 +45,16 @@ class BinSendCounterTestCase(base.TestCase):
def setUp(self):
super(BinSendCounterTestCase, self).setUp()
self.tempfile = self.temp_config_file_path()
pipeline_cfg_file = self.path_get('etc/ceilometer/pipeline.yaml')
with open(self.tempfile, 'w') as tmp:
tmp.write("[DEFAULT]\n")
tmp.write(
"rpc_backend=ceilometer.openstack.common.rpc.impl_fake\n")
tmp.write(
"pipeline_cfg_file=../etc/ceilometer/pipeline.yaml\n")
"pipeline_cfg_file=%s\n" % pipeline_cfg_file)

def test_send_counter_run(self):
subp = subprocess.Popen(["../bin/ceilometer-send-counter",
subp = subprocess.Popen([self.path_get('bin/ceilometer-send-counter'),
"--config-file=%s" % self.tempfile,
"--counter-resource=someuuid",
"--counter-name=mycounter"])
Expand All @@ -67,6 +68,8 @@ def setUp(self):
self.api_port = random.randint(10000, 11000)
self.http = httplib2.Http()
self.tempfile = self.temp_config_file_path()
pipeline_cfg_file = self.path_get('etc/ceilometer/pipeline.yaml')
policy_file = self.path_get('tests/policy.json')
with open(self.tempfile, 'w') as tmp:
tmp.write("[DEFAULT]\n")
tmp.write(
Expand All @@ -79,8 +82,10 @@ def setUp(self):
tmp.write(
"debug=true\n")
tmp.write(
"pipeline_cfg_file=../etc/ceilometer/pipeline.yaml\n")
self.subp = subprocess.Popen(["../bin/ceilometer-api",
"pipeline_cfg_file=%s\n" % pipeline_cfg_file)
tmp.write(
"policy_file=%s\n" % policy_file)
self.subp = subprocess.Popen([self.path_get('bin/ceilometer-api'),
"--config-file=%s" % self.tempfile])

def tearDown(self):
Expand Down
8 changes: 8 additions & 0 deletions tools/init_testr_if_needed.sh
@@ -0,0 +1,8 @@
#!/bin/sh
# this is rather stupid script is needed as testr init
# complains if there is already a repo.
if [ -d nova_tests/.testrepository ]
then
exit 0
fi
testr init -d nova_tests
5 changes: 4 additions & 1 deletion tools/test-requires
@@ -1,5 +1,6 @@
nose
distribute>=0.6.24
coverage
discover
mock
mox
fixtures>=0.3.12
Expand All @@ -17,4 +18,6 @@ netifaces
sphinx
docutils==0.9.1 # for bug 1091333, remove after sphinx >1.1.3 is released.
python-spidermonkey
python-subunit
testrepository>=0.0.13
testtools>=0.9.29
14 changes: 6 additions & 8 deletions tox.ini
Expand Up @@ -5,18 +5,16 @@ envlist = py26,py27,pep8
deps = -r{toxinidir}/tools/test-requires
-r{toxinidir}/tools/pip-requires
setenv = VIRTUAL_ENV={envdir}
NOSE_WITH_OPENSTACK=1
NOSE_OPENSTACK_COLOR=1
NOSE_OPENSTACK_RED=0.05
NOSE_OPENSTACK_YELLOW=0.025
NOSE_OPENSTACK_SHOW_ELAPSED=1
EVENTLET_NO_GREENDNS=yes
commands =
nosetests --no-path-adjustment --where=../nova_tests
nosetests --no-path-adjustment {posargs}
python setup.py testr --slowest --testr-args='--concurrency=1 {posargs}'
bash tools/init_testr_if_needed.sh
python setup.py testr --slowest --testr-args='--concurrency=1 --here=nova_tests {posargs}'
sitepackages = False

[testenv:cover]
commands = nosetests --no-path-adjustment --with-coverage --cover-erase --cover-package=ceilometer --cover-inclusive []
setenv = VIRTUAL_ENV={envdir}
commands = python setup.py testr --coverage

[testenv:pep8]
# Install bounded pep8/pyflakes first, then let flake8 install
Expand Down

0 comments on commit 1a723a0

Please sign in to comment.