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

How to use Hypothesis with function scoped fixtures? #3779

Closed
MaxG87 opened this issue Oct 30, 2023 · 1 comment
Closed

How to use Hypothesis with function scoped fixtures? #3779

MaxG87 opened this issue Oct 30, 2023 · 1 comment
Labels
interop how to play nicely with other packages

Comments

@MaxG87
Copy link

MaxG87 commented Oct 30, 2023

Hello,

I am a long-time user of hypothesis. Thank you very much for the great project! It is amazing.

Unfortunately, I somehow stopped to use hypothesis because it seems to be incompatible with pytest's function scoped fixtures. This means I often end up implementing test data generation on my own, which is much less elegant and much less comprehensive as it could be by using hypothesis. I am writing this issue to kindly ask whether there are updates or new workarounds I am not aware of.

I am aware of #377 and that it was closed some years ago. I am also aware of the documentation and possibility to suppress the HealthCheck and proceed with executing the function scoped fixture just once.

However, I would consider it not elegant to always tidy up at the end of a test using a function scoped fixture. Also, it might be error prone. I therefore wanted to ask whether there are some improvements I missed or that are planned.

Again, thank you for that fascinating library!

@Zac-HD
Copy link
Member

Zac-HD commented Oct 31, 2023

Hi Max! No changes to the situation in the docs - function-scoped fixtures are only executed once for all the examples; if that's OK you can just suppress the healthcheck. If not, then you'd need to find a non-fixture approach such as a context manager. We don't have any plans to change this, though I'd probably accept a PR which did so.

@Zac-HD Zac-HD closed this as completed Oct 31, 2023
@Zac-HD Zac-HD added the interop how to play nicely with other packages label Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interop how to play nicely with other packages
Projects
None yet
Development

No branches or pull requests

2 participants