【问题标题】:How to add Flake8 configuration file in pytest?如何在 pytest 中添加 Flake8 配置文件?
【发布时间】:2020-01-13 14:44:29
【问题描述】:

我想像这样使用 Flake8 运行 pytest:

python3 -m pytest --flake8

我也想使用以下参数运行 Flake8:

max-line-length = 120
select = E,W,F,N,C

我该怎么做? Creating setup.cfg 并没有改变任何内容:

[pytest]
flake8-max-line-length = 120
flake8-select = E,W,F,N,C

【问题讨论】:

    标签: python python-3.x pytest flake8


    【解决方案1】:

    编辑 pytest.ini(没有 setup.cfg 或任何其他配置文件)对我的情况有所帮助:

    [pytest]
    flake8-select = E,W,F,N,C
    flake8-max-line-length = 120
    flake8-ignore = E201 E231
    

    没有 flake8-ignore 我没有看到输出有任何差异。

    【讨论】:

      【解决方案2】:

      setup.cfg 的 pytest 部分从 version 4.0 开始是 [tool:pytest](根据 pytest 的删除过程在 4.1.0 中完全删除)

      免责声明:我是 pytest 的核心开发人员

      【讨论】:

      • 所以它是 [flake8:pytest] select = E,F,W,C max-line-length = 120 或 [tool:pytest] flake8-select = E,F,W,C flake8 -max-line-length = 120 这两个选项都没有解决问题。 :-(
      • 后者——你期望什么输出,你看到什么输出?
      • 我希望像 python3 -m pytest --flake8 --flake8-select=E,F,W,C --flake8-max-line-length=120 这样的东西。换句话说:好像我运行flake8 --max-line-length=120 --select=E,W,F,N,C
      • 请把你的输出和期望都放在问题中——这很有帮助。它对我有用,所以你没有提供所有必要的信息:)——你有其他 pytest 配置文件吗?检查pytest.ini / setup.cfg / tox.ini 以获取其他[pytest] / [tool:pytest] 配置。
      • 我不知道发生了什么,但我只更新了 pytest.ini(没有 setup.cfg)并添加了 flake8-ignore = E201 E231 行。之后 pytest 开始使用我的其他配置(如 flake8-max-line-length = 120)。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多