@@ -93,6 +93,21 @@ def skip_if_no_async_generators():
9393 )
9494
9595
96+ def skip_if_hypothesis_unavailable ():
97+ def hypothesis_unavailable ():
98+ try :
99+ import hypothesis # noqa: F401
100+ except ImportError :
101+ return True
102+
103+ return False
104+
105+ return pytest .mark .skipif (
106+ hypothesis_unavailable (),
107+ reason = "hypothesis not installed" ,
108+ )
109+
110+
96111@pytest .fixture
97112def cmd_opts (request ):
98113 reactor = request .config .getoption ("reactor" , "default" )
@@ -1255,3 +1270,81 @@ def test_should_not_run():
12551270 rr .stdout .no_re_match_line (pat = pattern )
12561271 else :
12571272 assert re .match (pattern , rr .stdout .str ()) is None
1273+
1274+
1275+ @skip_if_no_async_await ()
1276+ @skip_if_hypothesis_unavailable ()
1277+ def test_hypothesis_async_passes (testdir , cmd_opts ):
1278+ test_file = """
1279+ import hypothesis
1280+ import hypothesis.strategies
1281+
1282+ import pytest_twisted
1283+
1284+ @hypothesis.given(x=hypothesis.strategies.integers())
1285+ @pytest_twisted.ensureDeferred
1286+ async def test_async(x):
1287+ assert isinstance(x, int)
1288+ """
1289+ testdir .makepyfile (test_file )
1290+ rr = testdir .run (* cmd_opts , timeout = timeout )
1291+ assert_outcomes (rr , {"passed" : 1 })
1292+
1293+
1294+ @skip_if_hypothesis_unavailable ()
1295+ def test_hypothesis_inline_callbacks_passes (testdir , cmd_opts ):
1296+ test_file = """
1297+ import hypothesis
1298+ import hypothesis.strategies
1299+
1300+ import pytest_twisted
1301+
1302+ @hypothesis.given(x=hypothesis.strategies.integers())
1303+ @pytest_twisted.inlineCallbacks
1304+ def test_inline_callbacks(x):
1305+ assert isinstance(x, int)
1306+ return
1307+ yield
1308+ """
1309+ testdir .makepyfile (test_file )
1310+ rr = testdir .run (* cmd_opts , timeout = timeout )
1311+ assert_outcomes (rr , {"passed" : 1 })
1312+
1313+
1314+ @skip_if_no_async_await ()
1315+ @skip_if_hypothesis_unavailable ()
1316+ def test_hypothesis_async_fails (testdir , cmd_opts ):
1317+ test_file = """
1318+ import hypothesis
1319+ import hypothesis.strategies
1320+
1321+ import pytest_twisted
1322+
1323+ @hypothesis.given(x=hypothesis.strategies.integers())
1324+ @pytest_twisted.ensureDeferred
1325+ async def test_async(x):
1326+ assert isinstance(x, str)
1327+ """
1328+ testdir .makepyfile (test_file )
1329+ rr = testdir .run (* cmd_opts , timeout = timeout )
1330+ assert_outcomes (rr , {"failed" : 1 })
1331+
1332+
1333+ @skip_if_hypothesis_unavailable ()
1334+ def test_hypothesis_inline_callbacks_fails (testdir , cmd_opts ):
1335+ test_file = """
1336+ import hypothesis
1337+ import hypothesis.strategies
1338+
1339+ import pytest_twisted
1340+
1341+ @hypothesis.given(x=hypothesis.strategies.integers())
1342+ @pytest_twisted.inlineCallbacks
1343+ def test_inline_callbacks(x):
1344+ assert isinstance(x, str)
1345+ return
1346+ yield
1347+ """
1348+ testdir .makepyfile (test_file )
1349+ rr = testdir .run (* cmd_opts , timeout = timeout )
1350+ assert_outcomes (rr , {"failed" : 1 })
0 commit comments