diff --git a/swh/storage/pytest_plugin.py b/swh/storage/pytest_plugin.py --- a/swh/storage/pytest_plugin.py +++ b/swh/storage/pytest_plugin.py @@ -31,12 +31,7 @@ """ yield { "cls": "local", - "db": "postgresql://{user}@{host}:{port}/{dbname}".format( - host=postgresql_proc.host, - port=postgresql_proc.port, - user="postgres", - dbname="tests", - ), + "db": swh_storage_postgresql.dsn, "objstorage": {"cls": "memory", "args": {}}, "check_config": {"check_write": True}, } @@ -61,6 +56,7 @@ :returns: postgresql client """ config = factories.get_config(request) + if not psycopg2: raise ImportError("No module named psycopg2. Please install it.") proc_fixture = request.getfixturevalue(process_fixture_name) @@ -70,17 +66,17 @@ pg_port = proc_fixture.port pg_user = proc_fixture.user pg_options = proc_fixture.options - pg_db = db_name or config["dbname"] + pg_dbname = db_name or config["dbname"] with SwhDatabaseJanitor( pg_user, pg_host, pg_port, - pg_db, + pg_dbname, proc_fixture.version, dump_files=dump_files, ): connection = psycopg2.connect( - dbname=pg_db, + dbname=pg_dbname, user=pg_user, host=pg_host, port=pg_port, @@ -92,7 +88,7 @@ return postgresql_factory -swh_storage_postgresql = postgresql_fact("postgresql_proc") +swh_storage_postgresql = postgresql_fact("postgresql_proc", db_name="storage") # This version of the DatabaseJanitor implement a different setup/teardown