From 4a2866854242545f885bfe3b0173fc44d3c3aa4d Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Wed, 28 Aug 2013 19:08:07 +0400 Subject: [PATCH] Move tests to root dirrectory and fix tox Move rally/rally/tests -> rally/tests Use sqlite in memory to be able to run tests parallel --- .testr.conf | 2 +- rally/db/api.py | 5 +++++ rally/db/sqlalchemy/api.py | 4 ++++ rally/test.py | 11 ++++------- run_tests.sh | 2 +- {rally/tests => tests}/__init__.py | 0 {rally/tests => tests}/db/__init__.py | 0 {rally/tests => tests}/db/test_db_api.py | 0 8 files changed, 15 insertions(+), 9 deletions(-) rename {rally/tests => tests}/__init__.py (100%) rename {rally/tests => tests}/db/__init__.py (100%) rename {rally/tests => tests}/db/test_db_api.py (100%) diff --git a/.testr.conf b/.testr.conf index 8eafec4eb7..2109af6ce0 100644 --- a/.testr.conf +++ b/.testr.conf @@ -1,4 +1,4 @@ [DEFAULT] -test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 ${PYTHON:-python} -m subunit.run discover -t ./ ./rally/tests $LISTOPT $IDOPTION +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 diff --git a/rally/db/api.py b/rally/db/api.py index 8f328dd6dc..a00aa0a2b8 100644 --- a/rally/db/api.py +++ b/rally/db/api.py @@ -49,6 +49,11 @@ _BACKEND_MAPPING = {'sqlalchemy': 'rally.db.sqlalchemy.api'} IMPL = db_api.DBAPI(backend_mapping=_BACKEND_MAPPING) +def db_cleanup(): + """Recreate engine.""" + IMPL.db_cleanup() + + def db_create(): """Initialize DB. This method will drop existing database.""" IMPL.db_create() diff --git a/rally/db/sqlalchemy/api.py b/rally/db/sqlalchemy/api.py index dd9901eb59..b7b0ad0576 100644 --- a/rally/db/sqlalchemy/api.py +++ b/rally/db/sqlalchemy/api.py @@ -30,6 +30,10 @@ def get_backend(): return sys.modules[__name__] +def db_cleanup(): + db_session.cleanup() + + def db_create(): models.create_db() diff --git a/rally/test.py b/rally/test.py index a3c32beb65..23063c1e4a 100644 --- a/rally/test.py +++ b/rally/test.py @@ -15,21 +15,18 @@ # License for the specific language governing permissions and limitations # under the License. -import fixtures - -from oslo.config import cfg from rally import db +from rally.openstack.common.fixture import config from rally.openstack.common import test -CONF = cfg.CONF - - -class DatabaseFixture(fixtures.Fixture): +class DatabaseFixture(config.Config): """Create clean DB before starting test.""" def setUp(self): super(DatabaseFixture, self).setUp() + db.db_cleanup() + self.conf.set_default('connection', "sqlite://", group='database') db.db_create() diff --git a/run_tests.sh b/run_tests.sh index 2e85548bf4..60f2af3a36 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -45,7 +45,7 @@ export PROJECT_NAME="rally" # if equals to 1 export OMIT_OSLO_FROM_COVERAGE=0 # path to directory with tests -export TESTS_DIR="rally/tests/" +export TESTS_DIR="tests/" export EGG_INFO_FILE="rally.egg-info/entry_points.txt" # run common test script diff --git a/rally/tests/__init__.py b/tests/__init__.py similarity index 100% rename from rally/tests/__init__.py rename to tests/__init__.py diff --git a/rally/tests/db/__init__.py b/tests/db/__init__.py similarity index 100% rename from rally/tests/db/__init__.py rename to tests/db/__init__.py diff --git a/rally/tests/db/test_db_api.py b/tests/db/test_db_api.py similarity index 100% rename from rally/tests/db/test_db_api.py rename to tests/db/test_db_api.py