You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
logging: pytest should allow users to know why a test was deselected #13617
Especially when using markers and complex testing scenarios, one would endup being surprised that some tests were deselected without a reason.
Very long time ago (3.x), pytest has some code that attempted to provide reason about this but this code was buggy and was removed.
While we might not want to pollute the default console logging, we would want to ensure that when running with -v (or more), decisions about marking tests as deselected are also logged, so users could figure out the likely wrong condition.
@The-Compiler I would like to work on this, but before starting to write any code, it would better to ensure that I am not trying to fix the wrong issue ;)
Not sure why me - sounds reasonable all in all, but I don't have a strong opinion on this (and I don't remember any such code being around, might have been before I got into pytest stuff).
To rephrase, is anyone is not against bringing back support for tracking deselection reason, I will attempt to make a change that is backwards compatible.
@nicoddemus I am also referring to markers, I want to track reasons when they are used too, not only pytest_deselected hook.
To rephrase, is anyone is not against bringing back support for tracking deselection reason, I will attempt to make a change that is backwards compatible.
I'm OK with it. Adding a reason parameter to pytest_deselected is simple and backward compatible. Other than that, you will need to update terminal.py to capture that reason and display it later somehow.
@nicoddemus I am also referring to markers, I want to track reasons when they are used too, not only pytest_deselected hook.
I just ran into this: Running a test suite, got no tests executed:
collected 4 items / 4 deselected / 0 selected
I haven't passed any deselection args on the cmdline so why tests were deselected is unknown to me. Even having a list of tests that were deselected would also be good.
But having some (possibly verbose-only) output like "deselected xxx (not matching yy)" would be very helpful
Activity
The-Compiler commentedon Jul 24, 2025
Not sure why me - sounds reasonable all in all, but I don't have a strong opinion on this (and I don't remember any such code being around, might have been before I got into pytest stuff).
nicoddemus commentedon Jul 24, 2025
To be clear, you mean deselecting tests via
pytest_deselected?RonnyPfannschmidt commentedon Jul 24, 2025
The hook never supported passing the reason and something random else was printed
.thats why i took it away
ssbarnea commentedon Jul 25, 2025
To rephrase, is anyone is not against bringing back support for tracking deselection reason, I will attempt to make a change that is backwards compatible.
@nicoddemus I am also referring to markers, I want to track reasons when they are used too, not only
pytest_deselectedhook.nicoddemus commentedon Jul 25, 2025
I'm OK with it. Adding a
reasonparameter topytest_deselectedis simple and backward compatible. Other than that, you will need to updateterminal.pyto capture that reason and display it later somehow.pytest.mark.skip,pytest.mark.skipif, andpytest.mark.xfailall havereasonarguments already. When given, they show up in the test terminal summary. Do you mean something else?feat(13617): record reason for deselection and allow it to be displayed
RonnyPfannschmidt commentedon Jul 25, 2025
We cannot add the parameter without call control in pluggy
Its external called without a entrypoint we control
RonnyPfannschmidt commentedon Jul 25, 2025
On second thought we can actually use the same hack that was used for implying psth vs fspath in hooks
webknjaz commentedon Jul 26, 2025
Here's a radical though: why not redesign the deselection mechanics? Perhaps, have a new hook instead. Currently, making use of it is rather involved as it requires interfacing two tightly coupled things: https://github.com/aio-libs/multidict/blob/bc86d23/tests/conftest.py#L189-L210.
RonnyPfannschmidt commentedon Jul 26, 2025
The idea of such a api was on the table back in 2016 there just was no followup
In particular since doing this right requires retirement of the modifyitems hook
Flamefire commentedon Feb 20, 2026
I just ran into this: Running a test suite, got no tests executed:
I haven't passed any deselection args on the cmdline so why tests were deselected is unknown to me. Even having a list of tests that were deselected would also be good.
But having some (possibly verbose-only) output like "deselected xxx (not matching yy)" would be very helpful
terminal: list deselected items and their reason at -v
terminal: list deselected items and their reason at -v
terminal: list deselected items and their reason at -v
terminal: list deselected items and their reason at -v
terminal: list deselected items and their reason at -v