Warn when calling `pytest.skip()` during teardown?
During one of my trainings, a participant experimented with something like:
import pytest
@pytest.fixture
def fixt():
yield
pytest.skip()
def test_fixt(fixt):
pass
which currently results in:
test_x.py::test_fixt PASSED
test_x.py::test_fixt SKIPPED
and 1 passed, 1 skipped in ...s.
The known double-reporting issue aside: Does it really make sense to allow skipping during teardown at all? IMHO skipping only makes sense during a test (and pytest.skip in a fixture conceptually also skips the test). Should pytest.skip() during teardown perhaps be a warning of some sorts instead?
cc @ego-thales since you showed a snippet with this kind of thing over in #13537, so I wonder if you have an actual usecase for pytest.skip during teardown which I haven't considered.
i'd argue that we should deprecate skip in teardown and turn it into a failure - skip after the test is a lie
heck, skip inside the test is already pushing it but we concede so you can skip in the first few lines
but at teardown - no thats just wrong - lets make that invalid
I plan to work on the first deprecation stage. The current checkout reproduces 1 passed, 1 skipped with exit code 0. I propose a warning-only change that preserves current report outcomes under default filters and leaves setup and call skips unchanged.
Which warning category and removal release do you want? Does this scope include teardown exception groups that contain only skips?
Hi @AbhiramVSA , are you still planning to work on this? No rush at all. If you’re busy, I’d be happy to take it, or I can help with tests or docs if that’s useful. Thanks!