-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
postgresql_proc
is not working as expected.
#895
Comments
@Modjular the test database isn't created directly by postgresql_proc, but bu postgresql fixture. Instead of following the rollback approach every test, pytest-postgresql utilises database templates approach. Try following these steps: |
@fizyk Thanks for the response. Do you have any insight on the performance impacts of running it this way? My test suite (30 small unittests) used to run in under 500ms, but after some changes (fixtures, scoping, It's definitely possible that any of the other factors are to blame, but am I crazy for wondering if it should be faster? |
@Modjular I ran into the same surprise as you and wanted the db initialization/teardown to happen at the session level not the function level. It was pretty easy to make it work with the @pytest.fixture(scope="session")
def postgres_db(postgresql_proc: PostgreSQLExecutor) -> Iterator[PostgreSQLExecutor]:
with DatabaseJanitor(
postgresql_proc.user,
postgresql_proc.host,
postgresql_proc.port,
postgresql_proc.dbname,
postgresql_proc.version,
postgresql_proc.password,
):
yield postgresql_proc Then inject IMO a really nice enhancement would be to be able to specify the scope of the postgresql_proc = factories.postgresql_proc(load=[load_database])
postgresql = factories.postgresql('postgresql_proc', scope="session") # scope defaults to "function" |
FYI I added #897 to address the capability to have a session-scoped postgresql fixture to remove the need for the explicit |
@Modjular I did some performance checks when I introduced and the performance of the templating database should be on par with transaction rollback. |
What action do you want to perform
I want to:
What are the results
What are the expected results
No error
The text was updated successfully, but these errors were encountered: