Skip to content

Commit 8ef4193

Browse files
committed
hack running with hypothesis, maybe
1 parent a488312 commit 8ef4193

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

pytest_twisted.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,27 +365,28 @@ def pytest_pyfunc_call(pyfuncitem):
365365
# TODO: only handle 'our' tests? what is the point of handling others?
366366
# well, because our interface allowed people to return deferreds
367367
# from arbitrary tests so we kinda have to keep this up for now
368-
_run_inline_callbacks(_async_pytest_pyfunc_call, pyfuncitem)
369-
return not None
368+
f = pyfuncitem.obj.hypothesis.inner_test
369+
pyfuncitem.obj.hypothesis.inner_test = lambda **kwargs: _run_inline_callbacks(_async_pytest_pyfunc_call, pyfuncitem, f, kwargs)
370+
return None
370371

371372

372373
@defer.inlineCallbacks
373-
def _async_pytest_pyfunc_call(pyfuncitem):
374+
def _async_pytest_pyfunc_call(pyfuncitem, f, kwargs):
374375
"""Run test function."""
375-
kwargs = {
376+
kwargs.update({
376377
name: value
377378
for name, value in pyfuncitem.funcargs.items()
378379
if name in pyfuncitem._fixtureinfo.argnames
379-
}
380+
})
380381

381-
maybe_mark = _get_mark(pyfuncitem.obj)
382+
maybe_mark = _get_mark(f)
382383
if maybe_mark == 'async_test':
383-
result = yield defer.ensureDeferred(pyfuncitem.obj(**kwargs))
384+
result = yield defer.ensureDeferred(f(**kwargs))
384385
elif maybe_mark == 'inline_callbacks_test':
385-
result = yield pyfuncitem.obj(**kwargs)
386+
result = yield f(**kwargs)
386387
else:
387388
# TODO: maybe deprecate this
388-
result = yield pyfuncitem.obj(**kwargs)
389+
result = yield f(**kwargs)
389390

390391
defer.returnValue(result)
391392

test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pytest_twisted import ensureDeferred
2+
from hypothesis import given
3+
from hypothesis.strategies import integers
4+
5+
6+
async def test(x):
7+
assert isinstance(x, int)
8+
9+
original_test = test
10+
test = ensureDeferred(test)
11+
test = given(x=integers())(test)

0 commit comments

Comments
 (0)