Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor pytest_pycollect_makeitems (#421)
* refactor: Extracted logic for marking tests in auto mode into pytest_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> * refactor: Hoist up check for asyncio mode before trying to modify function 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> * refactor: Renamed _set_explicit_asyncio_mark and _has_explicit_asyncio_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> * refactor: Removed obsolete elif clause. 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> * refactor: Renamed the "holder" argument to _preprocess_async_fixtures to "processed_fixturedefs" to better reflect the purpose of the variable. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * refactor: Simplified branching structure of _preprocess_async_fixtures. 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> * refactor: Simplified logic in _preprocess_async_fixtures. Merged two if-clauses both of which cause the current fixturedef to be skipped. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * refactor: Extracted _inject_fixture_argnames from _preprocess_async_fixtures in order to improve readability. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * refactor: Extracted _synchronize_async_fixture from _preprocess_async_fixtures in order to improve readability. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
- Loading branch information