tox не работает при ImportError в python3.5

Я пытаюсь запустить пакет tox в своем проекте, который до сих пор работал нормально. Я запускаю Phycharm на Windows 10 Pro 64-bit, tox version 3.15.0, когда запускаю команду:

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\4\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 и this < / а>.

Это файл 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

person Or b    schedule 03.10.2020    source источник
comment
Не могли бы вы показать нам файлы conftest.py и tox ini.   -  person J.G.    schedule 05.10.2020
comment
@ J.G. обновлено, спасибо. До сих пор воспроизводит .. Думаю, что с файлами все в порядке. когда я запускаю одни и те же файлы на linux tox, работает отлично. Кроме того, когда я запускаю пакет, только что клонированный с GitHub (т.е. рабочую версию), ошибка все еще возникает на моей машине. Так что я думаю, что проблема где-то в моей машине.   -  person Or b    schedule 05.10.2020


Ответы (1)


Проблема, о которой вы сообщили, является актуальной проблемой в Python 3.5.0 !!

Вы можете проверить свою версию Python 3.5, введя такую ​​команду, как python3.5 --version, или просто введите python3.5 и взгляните на верхнюю часть вывода repl.

Вы можете решить проблему, установив любую более высокую версию Python 3.5, например 3.5.1 или даже самую последнюю версию 3.5.10.

Все это говорит о том, что Python 3.5 уже подходит к концу (https://www.python.org/downloads/ < / а>). Если нет важной причины, откажитесь от поддержки.

person J.G.    schedule 06.10.2020
comment
Решает мою проблему. Спасибо друг. Я использую tox для проверки совместимости моего кода с разными версиями Python, поэтому мне нужен Python3.5. - person Or b; 06.10.2020