Support async tests which use Hypothesis#102
Conversation
39c1f9d to
dc51d45
Compare
|
|
||
| @functools.wraps(func) | ||
| def inner(**kwargs): | ||
| loop = asyncio.get_event_loop_policy().new_event_loop() |
There was a problem hiding this comment.
Why not bare asyncio.new_event_loop() here?
There was a problem hiding this comment.
pytest-asyncio works slightly different with event loops:
- It installs the loop as default
- Restores previously used default loop after the test finishing
Does your change follow this behavior?
There was a problem hiding this comment.
Why not bare
asyncio.new_event_loop()here?
There are so many ways to get an event loop that I just copied the event_loop fixture; I assume there's a reason it was chosen there.
Does your change [set and restore the default loop]?
Async fixtures are not supported with Hypothesis tests, so there is no way to follow this behaviour. However this is only observable when the event_loop fixture has been overridden.
|
I think this is looking good! Looking forward to merging it in, as an avid user of Hypothesis :) Thank you for your contribution. Gonna leave it open for a few days to solicit additional comments. How difficult would it be in the future to add support for:
Having those as well would really rock. |
|
Awesome, glad I could help! Hopefully it will be released to users before the holidays 🎄:santa: Sync fixtures already work, with the notable caveat (HypothesisWorks/hypothesis#377) that function-scoped fixtures are only set up once for all test cases. Automatically converting function-scoped to 'test case scoped' fixtures is possible but nontrivial. Once that's done, supporting async function-scoped fixtures would be a few hours work plumbing it all together correctly. Async stateful testing would be obviously hugely valuable, but there's a catch: to make it repeatable (and powerful), Hypothesis would have to control the scheduling of tasks on the event loop. This is certainly possible, but out of scope for Hypothesis itself and I don't know enough about the asyncio internals to do it - though I'd be happy to consult on the Hypothesis side! See e.g. HypothesisWorks/hypothesis#1693 and links; there's also a prototype TLDR: both are difficult; not impossible but not priorities for me either. |
|
Thanks for your work on this! |
Closes #93.