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 async method fixture is run with different self
than the test method
#633
Comments
Linking the pytest-asyncio fix PR here: pytest-dev/pytest-asyncio#439 |
Meanwhile I suggest that you don't assign anything to the instance. That's not the correct way to use fixtures. |
Assigning something to an instance looks strange when using a fixture directly. We usually use a fixture with
In this case, assigning to an instance seems more justifiable. Or in this case assigning to the instance is also not the correct way? I didn't include |
Why not return the value from the fixture? |
To do this, you will have to specify in each test of class the use of the fixture directly instead of
Additionally, not all tests require data from the setup, but the setup process is still necessary. In this case it is easy to forget to specify setup fixture for test |
Is there something preventing you from using |
Thank you, now I understand your point. I haven't thought about using a fixture with Therefore, I think that this behavior can be left as is. It seems that the issue can be closed |
I disagree. This plugin should not make pytest deviate from how it normally works. |
Things to check first
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
AnyIO version
4.0.0
Python version
3.11.4
What happened?
I'm trying to use an fixture class method to initialize some data for tests and store it in attributes. With synchronous fixture everything works as expected, the filled attributes are available in the test methods. But attributes filled in async function are not available in test methods. This happens because different objects are passed as "self" for the fixture and the test method.
I found similar issue for pytest-asyncio which was fixed
How can we reproduce the bug?
Output:
The text was updated successfully, but these errors were encountered: