diff --git a/.testr.conf b/.testr.conf index c65c9314..9b4247c9 100644 --- a/.testr.conf +++ b/.testr.conf @@ -1,5 +1,5 @@ [DEFAULT] -test_command=SOLAR_DB=${SOLAR_DB:=sqlite://} \ - py.test ./solar --subunit $LISTOPT $IDOPTION +test_command=SOLAR_DB=${SOLAR_DB:='sqlite:////tmp/solar_{PID}.db'} \ + py.test --clean ./solar --subunit $LISTOPT $IDOPTION test_id_option=--subunit-load-list=$IDFILE test_list_option=--collectonly diff --git a/solar/__init__.py b/solar/__init__.py index 79d712dc..9de02223 100644 --- a/solar/__init__.py +++ b/solar/__init__.py @@ -4,5 +4,3 @@ except ImportError: pass else: monkey.patch_all() - from solar.dblayer.gevent_patches import patch_all - patch_all() diff --git a/solar/conftest.py b/solar/conftest.py new file mode 100644 index 00000000..5305b8b7 --- /dev/null +++ b/solar/conftest.py @@ -0,0 +1,34 @@ +# Copyright 2015 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os + +from solar.config import C +from solar import utils + + +C.solar_db = C.solar_db.format(PID=os.getpid()) + + +def pytest_addoption(parser): + parser.addoption( + "--clean", action="store_true", default=False, + help="Use this option for additional cleanup") + + +def pytest_unconfigure(config): + if config.getoption("clean"): + db, opts = utils.parse_database_conn(C.solar_db) + if db.mode == 'sqlite' and os.path.isfile(db.database): + os.unlink(db.database) diff --git a/solar/dblayer/__init__.py b/solar/dblayer/__init__.py index 80350229..fdea245a 100644 --- a/solar/dblayer/__init__.py +++ b/solar/dblayer/__init__.py @@ -1,3 +1,11 @@ +try: + from gevent import monkey +except ImportError: + pass +else: + from solar.dblayer.gevent_patches import patch_all + patch_all() + from solar.dblayer.model import ModelMeta from solar.config import C from solar.utils import parse_database_conn