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

Asynctest owner suggests switch to asyncmock #61

Closed
chbndrhnns opened this issue Jun 25, 2020 · 7 comments · Fixed by #69
Closed

Asynctest owner suggests switch to asyncmock #61

chbndrhnns opened this issue Jun 25, 2020 · 7 comments · Fixed by #69

Comments

@chbndrhnns
Copy link

When using the asynctest package (which is a dependency of respx) with Python 3.8+, there are deprecation warnings:

.venv/lib/python3.8/site-packages/asynctest/mock.py:448
  /Users/.../.venv/lib/python3.8/site-packages/asynctest/mock.py:448: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def wait_next(self, skip=0):

The author of asynctest suggests moving to asyncmock instead of resolving the issues (1, 2).

I am wondering if this would be an option for you to make respx future-proof.

@lundberg
Copy link
Owner

Thanks or raising this "issue".

I agree that we should use asyncmock for Python 3.8+. Easiest would be to move all patch imports to, lets say, a compat module that could dispatch which one to use depending on python version, asynctest or standard lib.

Any thoughts welcome!

@chbndrhnns
Copy link
Author

I am not very experienced in supporting multiple python versions so I cannot offer lots of thoughts here. What you suggest sounds reasonable, though.

I have not yet used asyncmock, either.

@hugovk
Copy link
Contributor

hugovk commented Jul 20, 2020

In the meantime, to silence the warnings in pytest, you can add something like this to pytest.ini, but note it'll silence them in your own code too:

[pytest]
filterwarnings =
    # respx/asynctest: https://github.com/lundberg/respx/issues/61
    ignore:"@coroutine" decorator is deprecated since Python 3.8, use "async def" instead:DeprecationWarning

@lundberg
Copy link
Owner

I've opened #69 . Since we're only patching methods and not really using async magic mocks, I was able to drop the asynctest dependency completely.

@lundberg
Copy link
Owner

@chbndrhnns , @hugovk please try out the PR. Note that the release of this will remove the dep of asynctest, so if you use it elsewhere in your tests, the dep needs to be added separate.

@hugovk
Copy link
Contributor

hugovk commented Aug 17, 2020

My unit tests are passing with the #69 branch 👍

@lundberg
Copy link
Owner

Thanks for testing @hugovk , 0.12.0 now released.

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 a pull request may close this issue.

3 participants