py.test deal with both pylint and flake8 when importing features from a module

Viewed 4243

So, I have roughly this code:

from .fixtures import some_fixture


def test_whatever(some_fixture):
    print(some_fixture)

I get two warnings from flake8 for this:

F401 '.fixtures.some_fixture' imported but unused

and

F811 redefinition of unused 'some_fixture' from line 1

I'm not going to move fixtures anywhere, but "decorating" every test definition and every import with noqa and pylint comments seems like a very sad and colorless life (especially so that sometimes it will silence a legitimate warning, s.a. when a fixture isn't really used).

What else can I do?

2 Answers

The better way is to place your fixtures in the conftest.py file which is the recommended location for shared fixtures.

They will be automatically discovered by pytest. You won't have to import them so no F401 and since the arguments won't be colliding with the imports no more F811.

Use flake8's and pylint's directives to disable checks:

from .fixtures import some_fixture  # noqa: F401; pylint: disable=unused-variable

def test_whatever(some_fixture):
    print(some_fixture)

There is no way around that.

Related