-
Notifications
You must be signed in to change notification settings - Fork 586
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
Improve healthcheck message when @given() wraps an async def function (which returns a coroutine object)
#3054
Comments
|
Hypothesis doesn't actually support We could use a more specific error message for coroutine objects though. |
@given() wraps an async def function (which returns a coroutine object)
|
@Zac-HD Thank you for your kind help and informative reply. I understand what happened now. Another problem is that the type checker I used, Pyright, detects a type error in the above code I presented. The type annotation of Do you have any advice in how to fix this type error? Anything that we can do in hypothesis or pytest-asyncio? Or maybe we should just use |
|
You'll need a def mark_asyncio(f: Coroutine[None, None, None]) -> Callable[..., None]:
# The actual replacement is handled by magic inside pytest-asyncio
# which understands Hypothesis, so we just ignore the types here.
return pytest.mark.asyncio(f) # type: ignore
@given(integers())
@mark_asyncio
async def test2(i: int) -> None:
await asyncio.sleep(0.001)
assert inc(i) == i + 1 |
|
@Zac-HD Thank you for your kind help. I tried your suggested workaround, and it worked perfectly. That's a very creative solution. |
6.15.0 - 2021-08-22 This release emits a more useful error message when @given() is applied to a coroutine function, i.e. one defined using async def (issue #3054). This was previously only handled by the generic return_value health check, which doesn’t direct you to use either a custom executor or a library such as pytest-trio or pytest-asyncio to handle it for you. 6.14.9 - 2021-08-20 This patch fixes a regression in Hypothesis 6.14.8, where from_type() failed to resolve types which inherit from multiple parametrised generic types, affecting the returns package (issue #3060). References: HypothesisWorks/hypothesis#3054 HypothesisWorks/hypothesis#3060 Signed-off-by: Tim Orling <timothy.t.orling@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
6.15.0 - 2021-08-22 This release emits a more useful error message when @given() is applied to a coroutine function, i.e. one defined using async def (issue #3054). This was previously only handled by the generic return_value health check, which doesn’t direct you to use either a custom executor or a library such as pytest-trio or pytest-asyncio to handle it for you. 6.14.9 - 2021-08-20 This patch fixes a regression in Hypothesis 6.14.8, where from_type() failed to resolve types which inherit from multiple parametrised generic types, affecting the returns package (issue #3060). References: HypothesisWorks/hypothesis#3054 HypothesisWorks/hypothesis#3060 (From OE-Core rev: 616f4ce10d4e09eaa89755e87e607011dc67441b) Signed-off-by: Tim Orling <timothy.t.orling@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
6.15.0 - 2021-08-22 This release emits a more useful error message when @given() is applied to a coroutine function, i.e. one defined using async def (issue #3054). This was previously only handled by the generic return_value health check, which doesn’t direct you to use either a custom executor or a library such as pytest-trio or pytest-asyncio to handle it for you. 6.14.9 - 2021-08-20 This patch fixes a regression in Hypothesis 6.14.8, where from_type() failed to resolve types which inherit from multiple parametrised generic types, affecting the returns package (issue #3060). References: HypothesisWorks/hypothesis#3054 HypothesisWorks/hypothesis#3060 (From OE-Core rev: 616f4ce10d4e09eaa89755e87e607011dc67441b) Signed-off-by: Tim Orling <timothy.t.orling@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
6.15.0 - 2021-08-22 This release emits a more useful error message when @given() is applied to a coroutine function, i.e. one defined using async def (issue #3054). This was previously only handled by the generic return_value health check, which doesn’t direct you to use either a custom executor or a library such as pytest-trio or pytest-asyncio to handle it for you. 6.14.9 - 2021-08-20 This patch fixes a regression in Hypothesis 6.14.8, where from_type() failed to resolve types which inherit from multiple parametrised generic types, affecting the returns package (issue #3060). References: HypothesisWorks/hypothesis#3054 HypothesisWorks/hypothesis#3060 Signed-off-by: Tim Orling <timothy.t.orling@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
6.15.0 - 2021-08-22 This release emits a more useful error message when @given() is applied to a coroutine function, i.e. one defined using async def (issue #3054). This was previously only handled by the generic return_value health check, which doesn’t direct you to use either a custom executor or a library such as pytest-trio or pytest-asyncio to handle it for you. 6.14.9 - 2021-08-20 This patch fixes a regression in Hypothesis 6.14.8, where from_type() failed to resolve types which inherit from multiple parametrised generic types, affecting the returns package (issue #3060). References: HypothesisWorks/hypothesis#3054 HypothesisWorks/hypothesis#3060 (From OE-Core rev: ca0039a6e5524ab1e74df285ce16460dc980da65) Signed-off-by: Tim Orling <timothy.t.orling@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
6.15.0 - 2021-08-22 This release emits a more useful error message when @given() is applied to a coroutine function, i.e. one defined using async def (issue #3054). This was previously only handled by the generic return_value health check, which doesn’t direct you to use either a custom executor or a library such as pytest-trio or pytest-asyncio to handle it for you. 6.14.9 - 2021-08-20 This patch fixes a regression in Hypothesis 6.14.8, where from_type() failed to resolve types which inherit from multiple parametrised generic types, affecting the returns package (issue #3060). References: HypothesisWorks/hypothesis#3054 HypothesisWorks/hypothesis#3060 (From OE-Core rev: ca0039a6e5524ab1e74df285ce16460dc980da65) Signed-off-by: Tim Orling <timothy.t.orling@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
The document states that besides running the test with pytest discovery, "we could also have run it explicitly ourselves". This is true for regular hypothesis-decorated tests. But it's not true for hypothesis-decorated coroutine tests.
Running these tests with pytest is fine. But if we run them explicitly,
test1()runs fine, buttest2()yieldshypothesis.errors.FailedHealthCheck: Tests run under @given should return None, but test2 returned <coroutine object test2 at 0x000001972E473F40> instead.Should we consider this a bug? Because this directly contradicts the instructions from the document.
The text was updated successfully, but these errors were encountered: