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

Warn on @given + function-scoped fixtures #2356

Merged
merged 1 commit into from
Feb 29, 2020

Conversation

Zac-HD
Copy link
Member

@Zac-HD Zac-HD commented Feb 15, 2020

Closes #377 by automating our response of "don't do that then".

Skips the warning for autouse=True fixtures purely because it's usually much more difficult to fix those. For example you can have fixtures skip tests with a mark (and all @given() tests are marked hypothesis by our plugin), but this wouldn't support our own time-mocking system which inherits function-scoped-ness from monkeypatch and should apply to @given() tests.

So I'd call this two parts education, one part enforcement of good practice, and one part pragmatic non-enforcement.

@Zac-HD Zac-HD added legibility make errors helpful and Hypothesis grokable interop how to play nicely with other packages labels Feb 15, 2020
Function-scoped fixtures expect to be reset between every test, but this isn't the case between Hypothesis test cases - which will probably cause trouble.
@Zac-HD Zac-HD merged commit f6216f4 into HypothesisWorks:master Feb 29, 2020
@Zac-HD Zac-HD deleted the fixture-scope-warning branch February 29, 2020 22:01
@The-Compiler
Copy link
Contributor

I feel like this warning is probably too strict - I opened a discussion here: #2370

@MPvHarmelen
Copy link

Irrespective of whether this warning is too strict: what is the alternative of a function scoped fixture and could we get the warning message to reference the alternative?

This in the line of thought: "Don't tell people what they shouldn't do, but what they should."

MPvHarmelen added a commit to MPvHarmelen/hypothesis that referenced this pull request Apr 5, 2020
Like this users will know what to do when getting this warning. See HypothesisWorks#2356.
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 legibility make errors helpful and Hypothesis grokable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pytest function scoped fixtures should run once per example, not once per test
5 participants