Skip to content

pytest_fixture_setup hook - fixtures can return None #2698

@uSpike

Description

@uSpike

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortopic: fixturesanything involving fixtures directly or indirectlytype: docsdocumentation improvement, missing or needing clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions