Fixes for running tests
This commit is contained in:
parent
addb797acc
commit
db9e0f6ba3
2 changed files with 12 additions and 3 deletions
|
@ -24,13 +24,22 @@ from initdb import initialize_database, populate_database
|
|||
from path_converters import APIRepositoryPathConverter, RegexConverter, RepositoryPathConverter
|
||||
from test.testconfig import FakeTransaction
|
||||
|
||||
INIT_DB_PATH = 0
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@lru_cache(maxsize=1) # Important! pytest is calling this multiple times (despite it being session)
|
||||
def init_db_path(tmpdir_factory):
|
||||
""" Creates a new database and appropriate configuration. Note that the initial database
|
||||
is created *once* per session. In the non-full-db-test case, the database_uri fixture
|
||||
makes a copy of the SQLite database file on disk and passes a new copy to each test.
|
||||
"""
|
||||
# NOTE: We use a global here because pytest runs this code multiple times, due to the fixture
|
||||
# being imported instead of being in a conftest. Moving to conftest has its own issues, and this
|
||||
# call is quite slow, so we simply cache it here.
|
||||
global INIT_DB_PATH
|
||||
INIT_DB_PATH = INIT_DB_PATH or _init_db_path(tmpdir_factory)
|
||||
return INIT_DB_PATH
|
||||
|
||||
def _init_db_path(tmpdir_factory):
|
||||
if os.environ.get('TEST_DATABASE_URI'):
|
||||
return _init_db_path_real_db(os.environ.get('TEST_DATABASE_URI'))
|
||||
|
||||
|
|
Reference in a new issue