jllorencetti / pytest-deadfixtures

Plugin to list unused fixtures in your tests
MIT License
153 stars 16 forks source link

`pytest.mark.usefixtures` fixtures marked as unused #10

Closed yedpodtrzitko closed 6 years ago

yedpodtrzitko commented 6 years ago

Hi, this library is quite helpful, thanks for creating it.

However there's an issue when marker pytest.mark.usefixtures [1] is used - such fixture is marked as unused anyway.

Cheers, yed

[1] https://docs.pytest.org/en/latest/fixture.html#using-fixtures-from-classes-modules-or-projects

jllorencetti commented 6 years ago

hi @yedpodtrzitko, thanks for taking your time to open this issue.

that's strange, this behavior should be covered already in this test. could you provide more details?

yedpodtrzitko commented 6 years ago

Thanks for your answer. That's really strange, indeed.

The fixtures in project I was testing it with are quite mess, so I'll try extract a minimal reproducible example.

jllorencetti commented 6 years ago

@yedpodtrzitko could you please try to replicate this problem again with the newest version 1.0.1? two fixes are made into this release that can solve this :)

yedpodtrzitko commented 6 years ago

Hi, sorry for no response from my side ...priorities.

Anyway, I tried to update to the new version. The output is much cleaner now. Before this release, there was a lot of items in the output as this:

Fixture name: transfers, location: <string>:3
Fixture name: transfers__bid, location: <string>:3
Fixture name: transfers__booking, location: <string>:3
Fixture name: transfers__created_at, location: <string>:3
Fixture name: transfers__tid, location: <string>:3
Fixture name: transfers__updated_at, location: <string>:3

Now this is gone, which is great. There is only one fixture in the output left, which is reported as unused, even if it is used. But after investigating a bit, I figured out the reason - the actual test was missing test_ in the name of its function, so the test collector skiped it, and the test never run.

So the reporting is actually correct, but for a different reason than I thought. Example below:

import pytest

@pytest.fixture
def mock_errorlib(mocker):
    return mocker.patch('api_clients.emailing.errorlib')

def send_extras_failed(mock_errorlib):  # this is the "test", which is using fixture, but it doesnt run
    assert mock_errorlib.sentry_client.captureException.callc_count == 1

This makes me think if it would be possible to make the output somehow hinting, that maybe the fixture is used, but for a thing, which is not a test. But that's definitely out of scope of this issue, so I'm gonna close it.

Thanks for your response, keep up the great work 👍