gpt4 book ai didi

python - 如何让 Flake8 处理 F811 错误?

转载 作者:太空宇宙 更新时间:2023-11-03 11:20:31 25 4
gpt4 key购买 nike

我们使用 flake8 来测试我们的代码,我们使用 pytest 和 fixtures。以下代码:

from staylists.tests.fixtures import fixture1  # noqa: F401

def test_case(fixture1): # noqa: F811
# Test goes here
assert 1 == 1

在 linting 期间生成 lib/python/test.py:3:1: F811 redefinition of unused 'fixture1' from line 1 错误。

  • 为什么它会忽略 noqa 标志?
  • 是否有更好的方法来避免标记此错误?

最佳答案

F401 和 F811 错误可以通过将所有灯具移动到 conftest.py 文件中来避免。 Pytest 自动加载此文件并使所有测试中的所有固定装置可用,即使没有显式导入语句也是如此。

有关该文件的更多讨论可在此处找到:In py.test, what is the use of conftest.py files?

关于python - 如何让 Flake8 处理 F811 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43746413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com