From db9e0f6ba3afbbe1239f69a70282ead2753b5640 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 1 Nov 2018 13:36:59 -0400 Subject: [PATCH] Fixes for running tests --- requirements-tests.txt | 4 ++-- test/fixtures.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 435f7c1fe..7c011e4a5 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,8 +1,8 @@ +pytest pytest-cov python-coveralls pytest-flask pytest-runner pytest-xdist pytest-timeout --e git+https://github.com/ant31/pytest-sugar.git#egg=pytest-sugar --e git+https://github.com/ant31/pytest.git#egg=pytest +-e git+https://github.com/ant31/pytest-sugar.git#egg=pytest-sugar \ No newline at end of file diff --git a/test/fixtures.py b/test/fixtures.py index 67a973992..f30fc0394 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -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'))