Skip to content

Warn on @given + function-scoped fixtures#2356

Merged
Zac-HD merged 1 commit intoHypothesisWorks:masterfrom
Zac-HD:fixture-scope-warning
Feb 29, 2020
Merged

Warn on @given + function-scoped fixtures#2356
Zac-HD merged 1 commit intoHypothesisWorks:masterfrom
Zac-HD:fixture-scope-warning

Conversation

@Zac-HD
Copy link
Copy Markdown
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
@Zac-HD Zac-HD requested a review from DRMacIver February 15, 2020 06:51
@Zac-HD Zac-HD force-pushed the fixture-scope-warning branch from c4dc452 to ddd072c Compare February 15, 2020 10:18
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 force-pushed the fixture-scope-warning branch from ddd072c to be3f412 Compare February 15, 2020 10:43
@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
Copy Markdown
Contributor

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

@MPvHarmelen
Copy link
Copy Markdown

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