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

Refactor pytest_pycollect_makeitems #421

Merged

Conversation

seifertm
Copy link
Contributor

@seifertm seifertm commented Oct 8, 2022

Pytest-asyncio essentially performs custom collection logic in pytest_pycollect_makeitem. This PR splits up the handling of async fixtures and async tests during test collection, renames a couple of thins, and extracts more fine-grained functions from _preprocess_async_fixtures. The goal of this PR is to make the code easier to understand.

This is a result of my investigation into #204.

…collection_modifyitems.

pytest_pycollect_makeitem currently calls `Collector._genfunctions`, in order to delegate further collection of test items to the current pytest collector. It does so only to add the asyncio mark to async tests after the items have been collected.

Rather than relying on a call to the protected `Collector._genfunctions` method the marking logic was moved to the pytest_collection_modifyitems hook, which is called at the end of the collection phase. This change removes the call to protected functions and makes the code easier to understand.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…ction items.

pytest_collection_modifyitems has no effect when asyncio mode is not set to AUTO. Moving the mode check out of the loop prevents unnecessary work.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…o_mark to _make_asyncio_fixture_function and _is_asyncio_fixture_function, respectively.

The new names reflect the purpose of the functions, instead of what they do. The new names also avoid confusion with pytest markers by not using "mark" in their names.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
Legacy mode has been removed, so we don't need an elif to check if we're in AUTO mode.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
… to "processed_fixturedefs" to better reflect the purpose of the variable.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
It is safe to call _make_asyncio_fixture_function without checking whether the fixture function has been converted to an asyncio fixture function, because each fixture is only processed once in the loop.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
Merged two if-clauses both of which cause the current fixturedef to be skipped.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…ixtures in order to improve readability.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…_fixtures in order to improve readability.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
@seifertm seifertm merged commit 907c461 into pytest-dev:master Oct 11, 2022
@seifertm seifertm deleted the refactor-pytest-collection-makeitems branch October 23, 2023 06:16
@seifertm seifertm restored the refactor-pytest-collection-makeitems branch October 23, 2023 08:17
@seifertm seifertm deleted the refactor-pytest-collection-makeitems branch October 23, 2023 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant