Make @fixture
and @parametrize
async aware
#301
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make
_decorate_fixture_plus
and_parametrize_plus
async aware by forwarding the function characteristics (coroutine (Python 3.5+) / asyncgen (Python 3.6+)) properly. Also useyield from
for Python 3.3+.I did not touch
@parametrize_with_cases
, since i am unsure if it even makes sense to have async cases (these would have to be transformed into fixtures).There is no guarantee that this fix will work before Python 3.8 because of pytest internals (see below). Some async framework plugins workaround around that by providing a way to force a fixture to be async (mostly by offering their own
fixture
decorator) which is incompatible with this plugin)There is one big caveat: there are no test yet and i am unsure how to test.Because testing against just one async framework is not very helpful and practially all pytest plugins for the different async frameworks are mutually exclusive. Ideally I would want to check that the property of being a coroutines or async generators passes through the above mentioned functions/decorators. But since pytest internally uses
functools.wraps
, which in turn usesfunctools.partial
, andinspect.iscoroutinefunction
/inspect.isasyncgenfunction
only work forfunctools.partial
for python 3.8+, testing for older python versions might be difficult/impossible.fixes #286