Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make @fixture and @parametrize async aware #301

Merged
merged 8 commits into from
Oct 11, 2023
Merged

Conversation

jgersti
Copy link
Contributor

@jgersti jgersti commented Jun 16, 2023

Make _decorate_fixture_plus and _parametrize_plus async aware by forwarding the function characteristics (coroutine (Python 3.5+) / asyncgen (Python 3.6+)) properly. Also use yield 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 fixturedecorator) 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 uses functools.partial, and inspect.iscoroutinefunction/inspect.isasyncgenfunction only work for functools.partial for python 3.8+, testing for older python versions might be difficult/impossible.

fixes #286

@jgersti jgersti changed the title Make @fixture and @parametrize` async aware Make @fixture and @parametrize async aware Jun 16, 2023
@jgersti jgersti force-pushed the feature/283 branch 3 times, most recently from 5183753 to 18f3ee7 Compare June 22, 2023 11:36
@jgersti
Copy link
Contributor Author

jgersti commented Jun 22, 2023

Added test that check that the decorated function ist still an async generator, coroutine or generator.

Since there is no Python 3.6+ filter for the tests functions, any session for earlier python versions fails because of illegal syntax in the test.
All other session failures on my local machine are all also present on the current main branch.

@pmmmwh
Copy link

pmmmwh commented Sep 1, 2023

@smarie Is there any chance this can be reviewed 🙏🏻 ?

@jgersti
Copy link
Contributor Author

jgersti commented Sep 10, 2023

@smarie I would really appreciate that this gets merged soon, because this is the only blocker left for my codebase to switch from trio to anyio.

@smarie
Copy link
Owner

smarie commented Oct 4, 2023

Hi @jgersti and @pmmmwh , thanks for this proposal !
Sorry for the wait, last few months were crazy
Could you please pull the latest develop branch so that we can run against all python versions using nox+virtualenv?
Thanks !

@smarie smarie merged commit d1c8c55 into smarie:main Oct 11, 2023
49 checks passed
@smarie
Copy link
Owner

smarie commented Oct 11, 2023

Congrats for this nice piece of work @jgersti ! I am impressed by the overall quality and consistency, on a difficult topic, with multi-version support. Thanks ! Let's ship this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pytest_cases.parametrize() makes pytest.mark.anyio not working
3 participants