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 == True
Inside pytest.ini I have my database information specified:
postgresql_host=foo
postgresql_port=5432
postgresql_user=user
postgresql_password=pass
And my test.sql file has, along with a lot of other content:
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?
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
.sqlfile that I'm trying to use to populate a running database with as part of an integration test, so I'm usingpostgresql_noproc. The.sqlfile requires autocommit to be turned on, but I don't see a way to enforce this with the wayDatabaseJanitoris currently structured.My simplified Python code:
Inside
pytest.iniI have my database information specified:And my
test.sqlfile has, along with a lot of other content: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
kwargsI want to pass topsycopg.Connection()such asautocommit=True(they default it toFalse) via thepostgresql_optionskey inpytest.ini(or via some otheriniparameter, if there's a more suitable one), but these configurations are not passed to the connection constructor.DatabaseJanitor calls
_loader()here which then ultimately callspsycopg.connect()here, but only thehost,port,user,dbname, andpasswordarguments are supplied, so there's no way to provide additional configuration topsycopg.Is there another way to supply a
psycopg.Connectioninstance to theDatabaseJanitorsuch that I can configure it before the.sqlfile loading occurs, or can we adjust the loading functionality to pass through more arguments frompytest.ini?