Reordering tests with pytest_collection_modifyitems
hook fails
#12305
Labels
status: needs information
reporter needs to provide more information; can be closed after 2 or more weeks of inactivity
Hiya pytest folks! I've got the problem with pytest hooks. The checklist was checked as below:
pip list
from the virtual environment you are usingpytest version: 8.00
python version: 3.12.2
OS: python:dev-3.12-bookworm Debian container
Issue:
I'm trying to reorder execution reorder of my tests using
pytest_collection_modifyitems
hook as described in:https://docs.pytest.org/en/latest/reference/reference.html#pytest.hookspec.pytest_collection_modifyitems
I added the following code in the top dir
conftest.py
:I noticed that tests are not running in the expected order, so I added logging code at the end in the modified hook to double check if it's correct:
and indeed it is. If I however log items from session.items in
pytest_collection_finish(session: pytest.Session)
hook my order will not be there anymore.Interestingly enough, moving reorgering logic to
pytest_collection_finish
hook, solves the problem, though it feels like a hacky workaround.I see 3 potential causes the the issue in hand:
pytest_collection_modifyitems
has a regression.I'd be grateful for the help with this one.
pip list:
The text was updated successfully, but these errors were encountered: