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

pytest_fixture_setup hook - fixtures can return None #2698

Closed
uSpike opened this issue Aug 16, 2017 · 1 comment
Closed

pytest_fixture_setup hook - fixtures can return None #2698

uSpike opened this issue Aug 16, 2017 · 1 comment
Labels
good first issue easy issue that is friendly to new contributor topic: fixtures anything involving fixtures directly or indirectly type: docs documentation improvement, missing or needing clarification

Comments

@uSpike
Copy link
Member

uSpike commented Aug 16, 2017

Hi, I was looking into implementing my own pytest_fixture_setup() and I noticed something interesting.

The hook is defined with @hookspec(firstresult=True) so, as the docstring describes it will stop at the first non-None result. However, it seems that this hook is supposed to return the return value of the fixture call, see https://github.com/pytest-dev/pytest/blob/master/_pytest/fixtures.py#L788. This is interesting, because a fixture could return None even though it has run. A trivial example:

The effect of this is that if I want to override pytest_fixture_setup() and not have it run again (from the internally defined hook), then I must return a non-None value. But, this may not reflect the actual value as returned from the fixture.

Am I missing something? Is this not a big deal? I think it's strange to return True even if it is not affecting my tests.

@RonnyPfannschmidt
Copy link
Member

@uSpike thansk for coming out and making this weakness that is based on the structure of how the plug-in system works obvious

i believe we should try to document that pitfall
in terms of consistent typing this is indeed a big deal

however the general expectation for a fixture is to actually return something,
strictly speaking - fixtures are dependency injection, so a fixture that doesn't return/yield a dependency to be injected is not doing what its supposed to do

@nicoddemus nicoddemus added topic: fixtures anything involving fixtures directly or indirectly type: docs documentation improvement, missing or needing clarification labels Sep 28, 2017
@nicoddemus nicoddemus added the good first issue easy issue that is friendly to new contributor label Jan 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor topic: fixtures anything involving fixtures directly or indirectly type: docs documentation improvement, missing or needing clarification
Projects
None yet
Development

No branches or pull requests

3 participants