Skip to content
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

Ability to make a noop fixture optionally dependant on proc fixture #890

Open
fizyk opened this issue Feb 13, 2024 · 3 comments
Open

Ability to make a noop fixture optionally dependant on proc fixture #890

fizyk opened this issue Feb 13, 2024 · 3 comments

Comments

@fizyk
Copy link
Member

fizyk commented Feb 13, 2024

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')
@mortalisk
Copy link

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.

@fizyk
Copy link
Member Author

fizyk commented Feb 19, 2024

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.

@mortalisk
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants