fixtures cannot be retrieved in pytest_runtest_makereport function for tests that are skipped during setup with the pytest.mark.skip marker #13101
Closed
Description
I am trying to retrieve the fixtures when a test has been skipped with the skip
marker.
But this is impossible because pytest doesn't pass the fixture of skipped tests during setup to the pytest_runtest_makereport function
Steps to reproduce:
- have a custom-made fixture called
my_fixture
inconftest.py
file
@pytest.fixture(scope='session')
def my_fixture(request):
pass
- write the following test:
@pytest.mark.skip
def test_skipped(my_fixture):
pass
- Add this function to the
conftest.py
file
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
if call.when == 'setup':
if report.skipped:
feature_request = item.funcargs['request']
my_fixture = feature_request.getfixturevalue("my_fixture")
# Do some stuff here
This piece of code doesn't work because item.funcargs = {}
and item.funcargs['request']
will raise an exception.
pytest doesn't retrieve the fixtures of skipped tests during setup. Why?
Tested with pytest 8.3.4