Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
harmin-parra opened this issue Jan 2, 2025 · 1 comment
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity topic: fixtures anything involving fixtures directly or indirectly type: question general question, might be closed after 2 weeks of inactivity

Comments

@harmin-parra
Copy link

harmin-parra commented Jan 2, 2025

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

@harmin-parra harmin-parra changed the title fixtures cannot be retrieved in pytest_runtest_makereport function for tests that are skipped with the pytest.mark.skip marker fixtures cannot be retrieved in pytest_runtest_makereport function for tests that are skipped during setup with the pytest.mark.skip marker Jan 2, 2025
@RonnyPfannschmidt RonnyPfannschmidt added type: question general question, might be closed after 2 weeks of inactivity topic: fixtures anything involving fixtures directly or indirectly labels Jan 2, 2025
@RonnyPfannschmidt
Copy link
Member

skipped tests don't get their fixtures filled

thats intended behavior

@RonnyPfannschmidt RonnyPfannschmidt added the status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity topic: fixtures anything involving fixtures directly or indirectly type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

2 participants