Skip to content

fixtures cannot be retrieved in pytest_runtest_makereport function for tests that are skipped during setup with the pytest.mark.skip marker #13101

Closed
@harmin-parra

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:

  1. have a custom-made fixture called my_fixture in conftest.py file
@pytest.fixture(scope='session')
def my_fixture(request):
    pass
  1. write the following test:
@pytest.mark.skip
def test_skipped(my_fixture):
    pass
  1. 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

Metadata

Assignees

No one assigned

    Labels

    status: needs informationreporter needs to provide more information; can be closed after 2 or more weeks of inactivitytopic: fixturesanything involving fixtures directly or indirectlytype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions