Closed michalkret closed 2 months ago
It's possible some other plugin reorders as well? Try like this:
@pytest.hookimpl(trylast=True)
def pytest_collection_modifyitems(config, items):
...
This issue is stale because it has the status: needs information
label and requested follow-up information was not provided for 14 days.
This issue was closed because it has the status: needs information
label and follow-up information has not been provided for 7 days since being marked as stale.
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_modifyitemsI 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 topytest_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: