Skip to content

@pytest.mark.usefixtures take no effects on fixtures #378

Closed

Description

@pytestbot

Originally reported by: BitBucket: oxyry, GitHub: oxyry


#!python
import pytest

@pytest.fixture
def app(scope='session'):
    print('fixture.app')

@pytest.fixture
def client(app):
    print('fixture.client')

@pytest.fixture
@pytest.mark.usefixtures('client')
def user_tom():
    print('user jessie')

def test_a(user_tom):
    print('test_a')
    assert False

In above code, 'client' fixture does not run, but it runs if put 'client' into user_tom()'s args list.


Activity

  1. pytestbot commented on Nov 1, 2013

    @pytestbot
    ContributorAuthor

    Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


    usefixtures (and other markers like parametrize for that matter) are not advertised to work on fixture functions, only on test functions. I don't see the advantage of providing usefixtures on a fixture function, in particular.

    If you like to see marker support on fixture functions, please open an enhancement issue and provide some ideas/input on the semantics on that. thanks.

  2. cjw296 commented on Jan 10, 2025

    @cjw296

    I wonder if it might be time to re-open this since in the era of linters and type checkers, this becomes more of a problem.

    In my case I have:

    @pytest.fixture()
    def superuser_headers(session_fixtures: SessionFixtures, session: Session) -> Headers:
        return session_fixtures.superuser_headers

    ...which will upset linters because session isn't used, but it is required for every downstream user of the superuser_headers fixture. Putting on the mark on every downstream user creates a lot of unnecessary text.

    I guess another option for an interface would be to allow something like:

    @pytest.fixture(uses=['session'])
    def superuser_headers(session_fixtures: SessionFixtures, session: Session) -> Headers:
        return session_fixtures.superuser_headers

    Anyway, happy to open a new issue if that's better but this feels like the best one for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions