Closed godlygeek closed 4 months ago
It looks anyio
stores some state on the test function, and pytest-memray
replaces the test function with a wrapper: https://github.com/bloomberg/pytest-memray/blob/0654e6b8c57cd98314c27484c280cb54c1b3bb94/src/pytest_memray/plugin.py#L213 Those two things don't play nicely with each other.
Actually, looks like pytest is storing that state on the test function. anyio
is just retrieving it.
We probably need to copy the test function's __dict__
over onto our wrapper.
@godlygeek thanks for the investigation.
My original analysis didn't spot the problem, actually. It's not that anyio isn't finding the state it expect on the wrapper, it's that anyio is completely ignoring the wrapper, because it only wants to process coroutine functions and ignore other stuff, and our wrapper isn't a coroutine function (even though calling it does return a coroutine, anyio is specifically looking only for async def
functions).
We might be able to get around that by defining an async def
wrapper if the function we're wrapping is an async def
coroutine...
This fix was released in pytest-memray 1.7.0
Thanks!
Hola @pablogsal,
I am facing the same issue: the async tests are skipped if we pass
--memray
argument to pytest.Steps to reproduce the issue:
Use the following test file:
test_async.py
Install required dependencies:
The test runs as expected if
--memray
is not passed:Output:
However, the test is skipped if we pass
--memray
:Output:
Originally posted by @albertvillanova in https://github.com/bloomberg/pytest-memray/discussions/101#discussioncomment-9738673