flake8 在 tox 测试环境中失败

flake8 fails in tox testing environment

下面是 运行 tox 上的失败消息。我没有在任何论坛上看到这个确切的错误报告。 这里的任何指导都会有很大帮助。

我正在 3.8-slim-buster docker 容器中调用 tox 并安装了所需的依赖项 - pip install tox flake8 black pylint

错误:

 File ".tox/lint/lib/python3.6/site-packages/hacking/core.py", line 185
    except ImportError, exc:
                      ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

.tox/lint/lib/python3.6/site-packages/flake8/plugins/manager.py", line 168, in load_plugin
    raise failed_to_load
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "H000" due to invalid syntax (core.py, line 185).

我的 tox.ini 文件。

  [tox]
    minversion = 1.8
    envlist =
        unit
        lint
        format-check
    skipsdist = true
    
    [testenv]
    usedevelop = true
    basepython = python3
    passenv = *
    setenv =
        COVERAGE_FILE={toxworkdir}/.coverage
        PIP_EXTRA_INDEX_URL=https://maven.com/artifactory/api/pypi/simple/
    extras =
        test
    
    [testenv:unit]
    commands =
        python -m pytest {posargs}
    
    [testenv:lint]
    commands =
        python -m flake8
    
    [testenv:format]
    commands =
        python -m black {toxinidir}
    
    [testenv:format-check]
    commands =
        python -m black --diff --check {toxinidir}
    
    [testenv:build-dists-local]
    usedevelop = false
    skip_install = true
    commands =
        python -m pep517.build \
          --source \
          --binary \
          --out-dir {toxinidir}/dist/ \
          {toxinidir}
    
    [testenv:build-dists]
    commands =
        rm -rfv {toxinidir}/dist/
        {[testenv:build-dists-local]commands}
    whitelist_externals =
        rm
    
    [testenv:publish-dists]
    commands =
        bash -c '\
          twine upload {toxinidir}/dist/*.whl \
            -u $TWINE_USERNAME \
            -p $TWINE_PASSWORD \
            --repository-url $TWINE_REPOSITORY \
        '
    whitelist_externals =
        bash
    
    [flake8]
    max-line-length = 100
    format = pylint
    exclude =
        .eggs/
        .tox/,
        .venv*,
        build/,
        dist/,
        doc/,
    #- [H106] Don't put vim configuration in source files.
    #- [H203] Use assertIs(Not)None to check for None.
    #- [H904] Delay string interpolations at logging calls.
    enable-extensions = H106,H203,H904
    ignore = E226,E302,E41
    
    [pytest]
    testpaths = test/
    addopts = -v -rxXs --doctest-modules --cov metarelease --cov-report term-missing --showlocals
    norecursedirs = dist doc build .tox .eggs
    
    [coverage:run]
    omit =
        metarelease/cmd/*
        metarelease/shell.py
    
    [coverage:report]
    fail_under =
        100

这既不是 flake8 也不是 tox 错误,而是 hacking 中的错误,当您仔细查看回溯时您会注意到。

语法

 File ".tox/lint/lib/python3.6/site-packages/hacking/core.py", line 185
    except ImportError, exc:

只在Python2有效,但是你用Python3.

我以前从未听说过 hacking 项目,但使用搜索引擎发现 https://pypi.org/project/hacking/

您应该向他们的错误跟踪器报告错误。