-
Notifications
You must be signed in to change notification settings - Fork 587
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
Can not run hypothesis as async test with 6.39.0 #3245
Comments
Thanks for reporting - I'll aim to have a fix, or at worst revert, out without 24 hours. |
In case this is useful, I hit this problem as well and did a small amount of digging. Locally, reverting the changes to hypothesis.internal.reflection.proxies is sufficient for tests to pass. I've also noticed that the inner function used by Not super familiar with hypothesis internals, but my quick guess is that previously, when using Now, with Here's an example. Definitions and imports: import asyncio
import hypothesis.internal.reflection
import pytest_asyncio
async def some_async_fn(a,b):
return a==b
wrapped_async_fn = pytest_asyncio.plugin.wrap_in_sync(None, some_async_fn, asyncio.get_event_loop()) Output: # Raw fn can handle both args and kwargs.
In [33]: await some_async_fn(1,2)
Out[33]: False
In [34]: await some_async_fn(a=1,b=2)
Out[34]: False
# Wrapped fn can only handle kwargs.
In [35]: wrapped_async_fn(1,2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [35], in <cell line: 1>()
----> 1 wrapped_async_fn(1,2)
TypeError: inner() takes 0 positional arguments but 2 were given
# This works.
In [36]: wrapped_async_fn(a=1,b=2)
# Old method of getting signature does not detect positional args for wrapped fn.
In [37]: hypothesis.internal.reflection.getfullargspec_except_self(some_async_fn)
Out[37]: FullArgSpec(args=['a', 'b'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={})
In [38]: hypothesis.internal.reflection.getfullargspec_except_self(wrapped_async_fn)
Out[38]: FullArgSpec(args=[], varargs=None, varkw='kwargs', defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={})
# New method has same output for both wrapped and raw.
In [39]: {k:v.kind for k,v in hypothesis.internal.reflection.get_signature(some_async_fn).parameters.items()}
Out[39]:
{'a': <_ParameterKind.POSITIONAL_OR_KEYWORD: 1>,
'b': <_ParameterKind.POSITIONAL_OR_KEYWORD: 1>}
In [40]: {k:v.kind for k,v in hypothesis.internal.reflection.get_signature(wrapped_async_fn).parameters.items()}
Out[40]:
{'a': <_ParameterKind.POSITIONAL_OR_KEYWORD: 1>,
'b': <_ParameterKind.POSITIONAL_OR_KEYWORD: 1>} |
Ah, that's the bug then, they're Nope, it's our fault, we changed from passing by name to passing positionally. This is a bad breaking change - I'll revert tonight and then open an issue to fix it properly soonish. |
Prior to #3241, def f(): ...
@given(st.integers())
@wraps(f)
def test(x): pass Before #3241: >>> test() # runs without problem After #3241: >>> test()
TypeError: f() got an unexpected keyword argument 'x' I believe this is due to changing |
That part is fine, the bit we need to revert is where we were passing arguments by name and now we're doing it by position. |
...which is in fact because we started following wrapper chains 🤦♂️ , @rsokl called it. |
Thanks for the super fast response and fix 🚀. |
While the pytest-asyncio team is not nearly as quick as the Hypothesis maintainers, we just released pytest-asyncio-0.18.2 which addresses the same issue on our end :) |
Legendary! I'd give you bonus points for (a) getting the report later, and (b) not causing the issue in the first place though 😅 |
I use pytest to run the tests:
Following test runs fine with 6.38.0:
And fails with 6.39.0:
Complete Log
It looks like the combination with pytest-async leads to confusion.
This blocks us from upgrading to latest hypothesis.
The text was updated successfully, but these errors were encountered: