How do I get Flake8 to work with F811 errors?

本秂侑毒 提交于 2019-12-21 17:39:15

问题


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):  # noqa: F811
    # Test goes here
    assert 1 == 1

Generates a lib/python/test.py:3:1: F811 redefinition of unused 'fixture1' from line 1 error during linting.

  • Why does it ignore the noqa flag?
  • Is there a better way to avoid flagging this error?

回答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?



来源:https://stackoverflow.com/questions/43746413/how-do-i-get-flake8-to-work-with-f811-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!