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 that are used in pytest.fixture(params=[...]) are marked as unused #28

Open
sobolevn opened this issue Nov 24, 2019 · 2 comments

Comments

@sobolevn
Copy link
Contributor

sobolevn commented Nov 24, 2019

I am using this approach in some of my fixtures:

@pytest.fixture()
def async_wrapper():
    """Fixture to convert all regular functions into async ones."""
    def factory(template: str) -> str:
        return template.replace(
            'def ', 'async def ',
        ).replace(
            'with ', 'async with ',
        ).replace(
            'for ', 'async for ',
        )
    return factory


@pytest.fixture()
def regular_wrapper():
    """Fixture to return regular functions without modifications."""
    def factory(template: str) -> str:
        return template
    return factory


@pytest.fixture(params=['async_wrapper', 'regular_wrapper'])
def mode(request):
    """Fixture that returns either `async` or regular functions."""
    return request.getfixturevalue(request.param)

And pytest --dead-fixtures marks both of them as unused:

» pytest --dead-fixtures --dup-fixtures

Hey there, I believe the following fixture(s) are not being used:
Fixture name: async_wrapper, location: tests/test_visitors/conftest.py:65
Fixture name: regular_wrapper, location: tests/test_visitors/conftest.py:79

What can be done to suppress this error?

Source code: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/test_visitors/conftest.py#L64-L89
Related: wemake-services/wemake-python-styleguide#1017

@burkestar
Copy link
Contributor

Due to the dynamic lookup that happens during execution of the fixture function, I assume this case will be difficult to recognize.

I at least added a unit test to cover this edge case (false positive) and refer back to this ticket: #31

@spumer
Copy link

spumer commented Dec 1, 2020

Any workaround for that case?

I think #23 can help solve it manually (per project)

And will be greatfull make support setup.cfg like per-file-ignore

used-fixtures-per-file =
   tests/conftest.py:async_wrapper,regular_wrapper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants