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

I want a rule that will detect unused fixture as argument and instruct to use pytest.mark.usefixtures instead #266

Open
ticosax opened this issue Oct 12, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@ticosax
Copy link

ticosax commented Oct 12, 2023

Rule request

Description

It's actually very close to PT019, except the fixture returns something.

@pytest.fixture()
def my_document(db):
    """pretend its fetched from a database"""
    return db.get_document(1)

# All good, the fixture is accessed
def test_check_something(my_document):
    assert my_document ==  {"name": "My Document"}

# Controversial, as my_document parameter is not accessed
def test_another_thing(my_document):
   """this test expect my_document to exist, even if it's not accessed."""
   assert len(db.get_documents()) == 1

I would like a rule that would recommend this construction for the second test.

@pytest.mark.usefixtures("my_document")
def test_another_thing():
    """this test expect my_document to exist, even if it's not accessed."""
   assert len(db.get_documents()) == 1

Rationale

Because my editor would not complain a parameter is not used. And would make explicit that a fixture is loaded only for its side effects.

Not sure it's desirable though. Happy to hear other thoughts on this

@ticosax ticosax added the enhancement New feature or request label Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant