tox 在 python3.5 中因 ImportError 失败

tox fails on ImportError in python3.5

我正在尝试 运行 tox 打包到我的项目中,目前为止运行良好。 我在 运行Windows 10 Pro 64-bittox version 3.15.0 上 Phycharm 当我 运行 命令时:

python -m tox --recreate

tox 测试通过 python3.6,3.7,3.8 但未通过 Python3.5.

这是我在 运行:

时得到的错误

python -m tox -epy35

GLOB sdist-make: C:\Users\Or\Documents\Studies\TAU\Term2\Project2\Source_code\pylint_upload\setup.py
py35 recreate: C:\Users\Or\Documents\Studies\TAU\Term2\Project2\Source_code\pylint_upload\.tox\py35
py35 installdeps: https://github.com/PyCQA/astroid/tarball/master#egg=astroid-master-2.0, coverage<5.0, mccabe, isort>=4.2.5,<5, pytest, pytest-xdist, pytest-benchmark, pytest-p
rofiling
py35 inst: C:\Users\Or\Documents\Studies\TAU\Term2\Project2\Source_code\pylint_upload\.tox\.tmp\package\pylint-2.6.1.dev1.zip
py35 installed: apipkg==1.5,astroid @ https://github.com/PyCQA/astroid/tarball/master,atomicwrites==1.4.0,attrs==20.2.0,colorama==0.4.3,coverage==4.5.4,execnet==1.7.1,gprof2dot=
=2019.11.30,importlib-metadata==2.0.0,iniconfig==1.0.1,isort==4.3.21,lazy-object-proxy==1.4.3,mccabe==0.6.1,packaging==20.4,pathlib2==2.3.5,pluggy==0.13.1,py==1.9.0,py-cpuinfo==
7.0.0,pylint @ file:///C:/Users/Or/Documents/Studies/TAU/Term2/Project2/Source_code/pylint_upload/.tox/.tmp/package/4/pylint-2.6.1.dev1.zip,pyparsing==2.4.7,pytest==6.1.0,pytest
-benchmark==3.2.3,pytest-forked==1.3.0,pytest-profiling==1.7.0,pytest-xdist==2.1.0,six==1.15.0,toml==0.10.1,typed-ast==1.4.1,wrapt==1.12.1,zipp==1.2.0
py35 run-test-pre: PYTHONHASHSEED='454'
py35 run-test: commands[0] | python -Wignore -m coverage run -m pytest --benchmark-disable 'C:\Users\Or\Documents\Studies\TAU\Term2\Project2\Source_code\pylint_upload/tests/'
ImportError while loading conftest 'C:\Users\Or\Documents\Studies\TAU\Term2\Project2\Source_code\pylint_upload\tests\conftest.py'.
..\tests\conftest.py:9: in <module>
    from pylint.testutils import MinimalTestReporter
py35\lib\site-packages\pylint\testutils.py:274: in <module>
    checkers.initialize(linter)
py35\lib\site-packages\pylint\checkers\__init__.py:64: in initialize
    register_plugins(linter, __path__[0])
py35\lib\site-packages\pylint\utils\utils.py:255: in register_plugins
    os.path.join(directory, filename)
py35\lib\site-packages\astroid\modutils.py:284: in load_module_from_file
    return load_module_from_modpath(modpath, path, use_sys)
py35\lib\site-packages\astroid\modutils.py:245: in load_module_from_modpath
    module = imp.load_module(curname, mp_file, mp_filename, mp_desc)
C:\Program Files\Python 3.5\lib\imp.py:234: in load_module
    return load_source(name, filename, file)
C:\Program Files\Python 3.5\lib\imp.py:172: in load_source
    module = _load(spec)
py35\lib\site-packages\pylint\checkers\async.py:16: in <module>
    from pylint.checkers import utils as checker_utils
py35\lib\site-packages\pylint\checkers\utils.py:640: in <module>
    def is_attr_private(attrname: str) -> Optional[Match[str]]:
C:\Program Files\Python 3.5\lib\typing.py:631: in __getitem__
    return Union[arg, type(None)]
C:\Program Files\Python 3.5\lib\typing.py:534: in __getitem__
    dict(self.__dict__), parameters, _root=True)
C:\Program Files\Python 3.5\lib\typing.py:491: in __new__
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
C:\Program Files\Python 3.5\lib\typing.py:490: in <genexpr>
    if any(issubclass(t1, t2)
E   TypeError: issubclass() arg 1 must be a class
ERROR: InvocationError for command 'C:\Users\Or\Documents\Studies\TAU\Term2\Project2\Source_code\pylint_upload\.tox\py35\Scripts\python.EXE' -Wignore -m coverage run -m pytest -
-benchmark-disable 'C:\Users\Or\Documents\Studies\TAU\Term2\Project2\Source_code\pylint_upload/tests/' (exited with code 4)
___________________________________________________________________________________ summary ____________________________________________________________________________________
ERROR:   py35: commands failed

我根本没有更改这个 conftest.py 文件,因为它曾经可以工作,所以我认为这不是这个错误的真正原因。 同样的命令 运行 在我的 Linux 机器上成功地在 Ubuntu 上,用于同一个项目。 我再次尝试 recreate tox,尝试克隆整个存储库并再次 运行 测试,还尝试了 this and .

这是 tox.ini 文件:

[tox]
minversion = 2.4
envlist = py35, py36, py37, py38, pypy, pylint, benchmark
skip_missing_interpreters = true

[testenv:pylint]
deps =
   git+https://github.com/pycqa/astroid@master
   pytest
commands =
    # This would be greatly simplified by a solution for https://github.com/PyCQA/pylint/issues/352
    pylint -rn --rcfile={toxinidir}/pylintrc --load-plugins=pylint.extensions.docparams, pylint.extensions.mccabe \
    {toxinidir}/pylint \
    {toxinidir}/tests/message/ \
    {toxinidir}/tests/checkers/ \
    {toxinidir}/tests/extensions/ \
    {toxinidir}/tests/utils/ \
    {toxinidir}/tests/acceptance/ \
    {toxinidir}/tests/conftest.py \
    {toxinidir}/tests/test_config.py \
    {toxinidir}/tests/test_func.py \
    {toxinidir}/tests/test_functional.py \
    {toxinidir}/tests/test_import_graph.py \
    {toxinidir}/tests/test_pragma_parser.py \
    {toxinidir}/tests/test_pylint_runners.py \
    {toxinidir}/tests/test_regr.py \
    {toxinidir}/tests/test_self.py \
    {toxinidir}/tests/unittest_config.py \
    {toxinidir}/tests/lint/ \
    {toxinidir}/tests/unittest_pyreverse_diadefs.py \
    {toxinidir}/tests/unittest_pyreverse_inspector.py \
    {toxinidir}/tests/unittest_pyreverse_writer.py \
    {toxinidir}/tests/unittest_reporters_json.py \
    {toxinidir}/tests/unittest_reporting.py

[testenv:formatting]
basepython = python3
deps =
    black==20.8b1
    isort==5.5.2
commands =
    black --check . --exclude="tests/functional/|tests/input|tests/extensions/data|tests/regrtest_data/|tests/data/|venv|astroid|.tox"
    isort . --check-only
changedir = {toxinidir}

[testenv:mypy]
basepython = python3
deps =
    typed-ast>=1.4
    mypy>=0.7,<1.0

commands =
    python -m mypy {toxinidir}/pylint/checkers --ignore-missing-imports {posargs:}

[testenv]
deps =
   https://github.com/PyCQA/astroid/tarball/master#egg=astroid-master-2.0
   coverage<5.0
   mccabe
   # isort 5 is not compatible with Python 3.5
   py35: isort>=4.2.5,<5
   pytest
   pytest-xdist
   pytest-benchmark
   pytest-profiling

setenv =
    COVERAGE_FILE = {toxinidir}/.coverage.{envname}

commands =
    ; Run tests, ensuring all benchmark tests do not run
    python -Wignore -m coverage run -m pytest --benchmark-disable {toxinidir}/tests/ {posargs:}

    ; Transform absolute path to relative path
    ; for compatibility with coveralls.io and fix 'source not available' error.
    ; If you can find a cleaner way is welcome
    python -c "import os;cov_strip_abspath = open(os.environ['COVERAGE_FILE'], 'r').read().replace('.tox' + os.sep + os.path.relpath('{envsitepackagesdir}', '{toxworkdir}') + os.sep, '');open(os.environ['COVERAGE_FILE'], 'w').write(cov_strip_abspath)"
changedir = {toxworkdir}


[testenv:spelling]
deps =
   https://github.com/PyCQA/astroid/tarball/master#egg=astroid-master-2.0
   pytest
   pytest-xdist
   pyenchant

commands =
    python -Wi -m pytest {toxinidir}/tests/ {posargs:} -k unittest_spelling

changedir = {toxworkdir}

[testenv:coveralls]
setenv =
    COVERAGE_FILE = {toxinidir}/.coverage
passenv =
    *
deps =
    coverage<5.0
    coveralls
skip_install = true
commands =
    python -m coverage combine
    python -m coverage report --rcfile={toxinidir}/.coveragerc -m
    - coveralls --rcfile={toxinidir}/.coveragerc
changedir = {toxinidir}

[testenv:coverage-erase]
setenv =
    COVERAGE_FILE = {toxinidir}/.coverage
deps =
    coverage<5
skip_install = true
commands =
    python -m coverage erase
changedir = {toxinidir}

[testenv:coverage-html]
setenv =
    COVERAGE_FILE = {toxinidir}/.coverage
deps =
    coverage<5
skip_install = true
commands =
    python -m coverage combine
    python -m coverage html --ignore-errors --rcfile={toxinidir}/.coveragerc
changedir = {toxinidir}

[testenv:docs]
usedevelop = True
changedir = doc/
extras =
  docs
commands =
  sphinx-build -W -b html -d _build/doctrees . _build/html

[testenv:benchmark]
deps =
   https://github.com/PyCQA/astroid/tarball/master#egg=astroid-master-2.0
   coverage<5.0
   mccabe
   pytest
   pytest-xdist
   pygal
   pytest-benchmark

commands =
    ; Run the only the benchmark tests, grouping output and forcing .json output so we
    ; can compare benchmark runs
    python -Wi -m pytest --exitfirst \
                         --failed-first \
                         --benchmark-only \
                         --benchmark-save=batch_files \
                         --benchmark-save-data \
                         --benchmark-autosave \
                         {toxinidir}/tests \
                         --benchmark-group-by="group" \
                         {posargs:}

changedir = {toxworkdir}

这是conftest.py:

# pylint: disable=redefined-outer-name
# pylint: disable=no-name-in-module
import os

import pytest

from pylint import checkers
from pylint.lint import PyLinter
from pylint.testutils import MinimalTestReporter


@pytest.fixture
def linter(checker, register, enable, disable, reporter):
    _linter = PyLinter()
    _linter.set_reporter(reporter())
    checkers.initialize(_linter)
    if register:
        register(_linter)
    if checker:
        _linter.register_checker(checker(_linter))
    if disable:
        for msg in disable:
            _linter.disable(msg)
    if enable:
        for msg in enable:
            _linter.enable(msg)
    os.environ.pop("PYLINTRC", None)
    return _linter


@pytest.fixture(scope="module")
def checker():
    return None


@pytest.fixture(scope="module")
def register():
    return None


@pytest.fixture(scope="module")
def enable():
    return None


@pytest.fixture(scope="module")
def disable():
    return None


@pytest.fixture(scope="module")
def reporter():
    return MinimalTestReporter

您报告的问题实际上是 Python 3.5.0 中的问题!!

您可以通过输入 python3.5 --version 之类的命令来检查您的 Python 3.5 版本,或者只需输入 python3.5 并查看 repl 输出的顶部。

您可以通过安装任何更高版本的 Python 3.5 来解决问题,例如 3.5.1 或最新版本 3.5.10。

这一切都说明了 - Python 3.5 已经结束(https://www.python.org/downloads/)。如无重要原因,请考虑放弃支持