From d18a7935e172c4fbc912a47e43c407da190cbadb Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 18 Oct 2018 14:42:54 -0400 Subject: [PATCH] Fix pytest fixture import issue with hashability of tmpdir_factory --- test/fixtures.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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'))