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

Handle bound fixture methods correctly #439

Merged
merged 1 commit into from Nov 11, 2022

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

@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!

pytest_asyncio/plugin.py Show resolved Hide resolved
pytest_asyncio/plugin.py Show resolved Hide resolved
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 requested review from seifertm and removed request for asvetlov and Tinche 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