6060 Unsatisfiable ,
6161 UnsatisfiedAssumption ,
6262)
63- from hypothesis .executors import new_style_executor
63+ from hypothesis .executors import default_new_style_executor , new_style_executor
6464from hypothesis .internal .compat import (
6565 PYPY ,
6666 bad_django_TestCase ,
@@ -1019,15 +1019,12 @@ def wrapped_test(*arguments, **kwargs):
10191019
10201020 if getattr (test , "is_hypothesis_test" , False ):
10211021 raise InvalidArgument (
1022- (
1023- "You have applied @given to the test %s more than once, which "
1024- "wraps the test several times and is extremely slow. A "
1025- "similar effect can be gained by combining the arguments "
1026- "of the two calls to given. For example, instead of "
1027- "@given(booleans()) @given(integers()), you could write "
1028- "@given(booleans(), integers())"
1029- )
1030- % (test .__name__ ,)
1022+ f"You have applied @given to the test { test .__name__ } more than "
1023+ "once, which wraps the test several times and is extremely slow. "
1024+ "A similar effect can be gained by combining the arguments "
1025+ "of the two calls to given. For example, instead of "
1026+ "@given(booleans()) @given(integers()), you could write "
1027+ "@given(booleans(), integers())"
10311028 )
10321029
10331030 settings = wrapped_test ._hypothesis_internal_use_settings
@@ -1039,12 +1036,28 @@ def wrapped_test(*arguments, **kwargs):
10391036 )
10401037 arguments , kwargs , test_runner , search_strategy = processed_args
10411038
1039+ if (
1040+ inspect .iscoroutinefunction (test )
1041+ and test_runner is default_new_style_executor
1042+ ):
1043+ # See https://github.com/HypothesisWorks/hypothesis/issues/3054
1044+ # If our custom executor doesn't handle coroutines, or we return an
1045+ # awaitable from a non-async-def function, we just rely on the
1046+ # return_value health check. This catches most user errors though.
1047+ raise InvalidArgument (
1048+ "Hypothesis doesn't know how to run async test functions like "
1049+ f"{ test .__name__ } . You'll need to write a custom executor, "
1050+ "or use a library like pytest-asyncio or pytest-trio which can "
1051+ "handle the translation for you.\n See https://hypothesis."
1052+ "readthedocs.io/en/latest/details.html#custom-function-execution"
1053+ )
1054+
10421055 runner = getattr (search_strategy , "runner" , None )
10431056 if isinstance (runner , TestCase ) and test .__name__ in dir (TestCase ):
10441057 msg = (
1045- "You have applied @given to the method %s , which is "
1058+ f "You have applied @given to the method { test . __name__ } , which is "
10461059 "used by the unittest runner but is not itself a test."
1047- " This is not useful in any way." % test . __name__
1060+ " This is not useful in any way."
10481061 )
10491062 fail_health_check (settings , msg , HealthCheck .not_a_test_method )
10501063 if bad_django_TestCase (runner ): # pragma: no cover
0 commit comments