Use isolated filebased sqlite for each test process

Changed configuration of testr to use file based sqlite database.
Database name will be finally configured in solar/conftest.py
for each process.
If --clean flag will be provided to py.test - database will be removed
after testrun.

All dblayer patches were removed from solar/__init__.py to
solar/dblayer/__init__.py to avoid patching of sqlite client

Change-Id: I615be46aecbb0b88a1088f5a379f10ba95ae9aad
This commit is contained in:
Dmitry Shulyak 2016-01-20 15:04:43 +02:00
parent cd809e8e83
commit 800a6e3182
4 changed files with 44 additions and 4 deletions

View File

@ -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

View File

@ -4,5 +4,3 @@ except ImportError:
pass
else:
monkey.patch_all()
from solar.dblayer.gevent_patches import patch_all
patch_all()

34
solar/conftest.py Normal file
View File

@ -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)

View File

@ -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