【问题标题】:Why does flake8 give different results for the same command locally and within tox?为什么 flake8 在本地和 tox 内对同一命令给出不同的结果?
【发布时间】:2020-04-03 08:32:05
【问题描述】:

我有一个 Python 项目,我使用 flake8 对代码进行 lint。

在本地,flake8 正确地提出了警告:

$ flake8 scripts src tests --ignore=W503,E501
src/projectname/workers/utils.py:22:20: W291 trailing whitespace

但是,tox 中的相同命令不会引发任何警告:

$ tox -e flake8

得到以下输出:

flake8 develop-inst-noop: /home/username/Projects/projectname
flake8 installed: alembic==0.9.8, ..., zipp==0.5.2
flake8 runtests: PYTHONHASHSEED='2190899390'
flake8 runtests: commands[0] | flake8 scripts src tests --ignore=W503,E501
________________________________ summary _________________________________
  flake8: commands succeeded
  congratulations :)

这是我的tox.ini 文件的内容:

[tox]
envlist = flake8,py36

[testenv]
changedir = {toxworkdir}/{envname}
usedevelop = True
install_command = pip install {opts} {packages}
deps =
    py36: pytest-cov
    py36: pytest
    flake8: flake8
setenv =
    COVERAGE_FILE = {toxinidir}/.coverage.{envname}
commands =
    py36: pytest {toxinidir}/tests --cov=projectname {posargs}
    flake8: flake8 scripts src tests --ignore=W503,E501
    ;       E501: line too long
    ;       W503: line break before binary operator

我检查了,在两个实验中,我都有flake8==3.7.9
为什么flake8tox 在这种情况下不应该返回任何错误代码?

【问题讨论】:

    标签: python tox flake8


    【解决方案1】:

    你的tox.ini 有:

    changedir = {toxworkdir}/{envname}
    

    这意味着当您在 tox 中运行 flake8 时,它会掉毛(不存在).tox/flake8/scripts/.tox/flake8/src/.tox/flake8/tests,因此您看不到错误(3.7.x 的行为是默默地忽略不存在的东西)

    请注意,在 flake8 3.8 中(在撰写本文时,尚未发布),这将再次成为错误 (E902):

    $ flake8 does-not-exist
    does-not-exist:0:1: E902 FileNotFoundError: [Errno 2] No such file or directory: 'does-not-exist'
    

    免责声明:我是flake8的当前维护者,也是tox的维护者之一

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-25
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      • 2017-04-29
      • 2021-12-07
      • 2020-10-15
      相关资源
      最近更新 更多