Skip to content

Conversation

@mjpieters
Copy link
Contributor

@mjpieters mjpieters commented Nov 6, 2022

When passed a bound fixture method, re-bind that method to the currently active instance.

The implementation follows how pytest handles bound fixtures, including how it'll always bind any fixture when fixturedef.unittest is true, and otherwise only if the fixture wasn't already bound or if bound to a an instance of the same class or a subclass thereof.

Fixes #197

@mjpieters mjpieters force-pushed the async_fixture_methods branch 7 times, most recently from cef53c9 to e69738a Compare November 6, 2022 23:44
@seifertm seifertm force-pushed the async_fixture_methods branch from e69738a to 6188089 Compare November 10, 2022 06:20
@seifertm
Copy link
Contributor

The CI runs the tests with -W error. For some reason, it pulled in the latest version of pytest. v7.2 introduces some deprecation warnings which, in turn, triggered errors. Therefore, I had to merge #438 first and rebase this PR.

Copy link
Contributor

@seifertm seifertm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great PR. Thank you!

When the current test request references an instance, bind the fixture function to that instance. When the unittest flag is set, this happens unconditionally, otherwise only if:

- the fixture wasn't bound already
- the fixture is bound to a compatible instance (the request.instance object has the same type or is a subclass of that type).

This follows what pytest does in such cases, exactly.
@mjpieters mjpieters force-pushed the async_fixture_methods branch from 6188089 to 8860dc5 Compare November 10, 2022 17:37
@mjpieters mjpieters requested review from seifertm and removed request for Tinche and asvetlov November 10, 2022 17:51
@seifertm seifertm enabled auto-merge (squash) November 11, 2022 15:28
@seifertm seifertm merged commit fe63e34 into pytest-dev:master Nov 11, 2022
@mjpieters mjpieters deleted the async_fixture_methods branch November 11, 2022 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

async method fixture is run with different self than the test method

2 participants