-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Thanks for the great package--I might be missing something, but am hitting an issue with one of my current use cases. I have an .sql file that I'm trying to use to populate a running database with as part of an integration test, so I'm using postgresql_noproc. The .sql file requires autocommit to be turned on, but I don't see a way to enforce this with the way DatabaseJanitor is currently structured.
My simplified Python code:
from pytest_postgresql import factories
postgresql_my_noproc = factories.postgresql_noproc(
load=["C:/test.sql"]
)
postgresql_my = factories.postgresql("postgresql_my_noproc")
def test_database(postgresql_my):
# Just invoke the fixture's SQL loading.
assert 1 == TrueInside pytest.ini I have my database information specified:
postgresql_host=foo
postgresql_port=5432
postgresql_user=user
postgresql_password=passAnd my test.sql file has, along with a lot of other content:
CREATE DATABASE test;Running this results in: psycopg.errors.ActiveSqlTransaction: CREATE DATABASE cannot run inside a transaction block, which makes sense.
Ideally I'd be able to specify the additional kwargs I want to pass to psycopg.Connection() such as autocommit=True (they default it to False) via the postgresql_options key in pytest.ini (or via some other ini parameter, if there's a more suitable one), but these configurations are not passed to the connection constructor.
DatabaseJanitor calls _loader() here which then ultimately calls psycopg.connect() here, but only the host, port, user, dbname, and password arguments are supplied, so there's no way to provide additional configuration to psycopg.
Is there another way to supply a psycopg.Connection instance to the DatabaseJanitor such that I can configure it before the .sql file loading occurs, or can we adjust the loading functionality to pass through more arguments from pytest.ini?