gpt4 book ai didi

python - 如何忽略 ‘imported but unused’ 文件中的 Pyflakes 错误 ‘__init__.py’?

转载 作者:太空狗 更新时间:2023-10-29 21:53:35 26 4
gpt4 key购买 nike

我将我的测试拆分到多个 Python 文件中:

tests
├── __init__.py
├── test_apples.py
└── test_bananas.py.py

我在“__init__.py”文件中导入测试:

from test_apples import ApplesTest
from test_bananas import BananasTest

但是在命令行上运行 Pyflakes:

pyflakes .

输出以下错误:

tests/__init__.py:1: [E] PYFLAKES:'ApplesTest' imported but unused
tests/__init__.py:2: [E] PYFLAKES:'BananasTest' imported but unused

最佳答案

要忽略“__init__.py”文件中的所有错误 F401(“已导入但未使用”),选项 ‘per-file-ignores’Flake8 的 3.7.0 版开始可用(更好的 Pyflakes)非常方便。它可以在命令行上使用:

flake8 --per-file-ignores="__init__.py:F401" .

或在配置文件中(‘.flake8’、‘setup.cfg’或‘tox.ini’):

[flake8]
per-file-ignores = __init__.py:F401

关于python - 如何忽略 ‘imported but unused’ 文件中的 Pyflakes 错误 ‘__init__.py’?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8427701/

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