Skip to content Skip to sidebar Skip to footer

How Do I Get Flake8 To Work With F811 Errors?

We're using flake8 to test our code, and we're using pytest with fixtures. The following code: from staylists.tests.fixtures import fixture1 # noqa: F401 def test_case(fixture1):

Solution 1:

The F401 and F811 errors can be avoided by moving all fixtures into the conftest.py file. Pytest loads this file automatically and makes all fixtures inside available in all tests, even without explicit import statements.

More discussion about the file can be found here: In py.test, what is the use of conftest.py files?

Solution 2:

There are two "best practices" for sharing fixtures:

  1. define them in a conftest above both test modules
    • pytest will automatically share them between the two tests
  2. define a pytest plugin which exposes fixtures
    • pytest will make your fixtures available to all tests

bringing a fixture into a scope via import side-effects will trigger the issues you're seeing and is not recommended

Post a Comment for "How Do I Get Flake8 To Work With F811 Errors?"