diff --git a/test/fixtures.py b/test/fixtures.py index e442234b8..3c0c1cde5 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -29,13 +29,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'))