pytest-postgresql icon indicating copy to clipboard operation
pytest-postgresql copied to clipboard

Ability to make a noop fixture optionally dependant on proc fixture

Open fizyk opened this issue 1 year ago • 3 comments

The goal is to provide an additional layer between process and client that would allow to provide additional, common data fixtures that would be available only for a subset of tests, not all of them.

The simplest way would be to make noop fixture optionally dependent on the process fixture.


from pytest_postgresql import factories

postgresql_my_proc = factories.postgresql_proc()
postgresql_additional = factories.postgresql_noproc(dbname="subset_of_heavy_tests", optional_proc="postgresql_my_proc", load=[Path("/path/to/heavy.sql")])
postgresql_heavy_subset = factories.postgresql('postgresql_additional')

fizyk avatar Feb 13 '24 13:02 fizyk

This sounds awesome.

This would basically do what we have now done (with quite a bit of pain and manual code). We have reused the proc instance, but make a separate db for it.

mortalisk avatar Feb 13 '24 14:02 mortalisk

Okay, that fixture would have to be separated at least by name from the proc/noproc duo:


from pytest_postgresql import factories

postgresql_my_proc = factories.postgresql_proc()
postgresql_table = factories.postgresql_table("postgresql_my_proc", dbname="subset_of_heavy_tests", optional_proc="postgresql_my_proc", load=[Path("/path/to/heavy.sql")])
postgresql_heavy_subset = factories.postgresql('postgresql_table')

A specialised table (from the outside) would be a better approach.

fizyk avatar Feb 19 '24 11:02 fizyk

What would that achieve? Can we then supply some command line arguments to skip the proc instantiation? anyway, we now simply have a branch in the conftest to either instantiate proc or noproc with same name, this works.

What we find now, is that after running tests once with noproc, the next time if fails because the DB is then already there. Would it be an idea to have an optional parameter to noproc to delete the DB if it already exists?

mortalisk avatar Feb 19 '24 11:02 mortalisk