# HG changeset patch # User Martin Bornhold # Date 2016-09-27 07:48:23 # Node ID cf699af2f344bdc3e52b9874cd71f4a8d3a7f744 # Parent 41b97db85451073bebced146461ce56246169c8a tests: Add a ``db`` fixture that initializes the database. This is quite useful if tests only need the database and not the whole app. Then only this fixture is needed instead of the full blown pylonsapp/app fixtures. diff --git a/rhodecode/tests/plugin.py b/rhodecode/tests/plugin.py --- a/rhodecode/tests/plugin.py +++ b/rhodecode/tests/plugin.py @@ -218,7 +218,7 @@ def app(request, pylonsapp, http_environ return app -@pytest.fixture() +@pytest.fixture(scope='session') def app_settings(pylonsapp, pylons_config): """ Settings dictionary used to create the app. @@ -234,6 +234,18 @@ def app_settings(pylonsapp, pylons_confi return settings +@pytest.fixture(scope='session') +def db(app_settings): + """ + Initializes the database connection. + + It uses the same settings which are used to create the ``pylonsapp`` or + ``app`` fixtures. + """ + from rhodecode.config.utils import initialize_database + initialize_database(app_settings) + + LoginData = collections.namedtuple('LoginData', ('csrf_token', 'user'))