Tox“错误:找不到文件:<项目名称>”

时间:2019-08-20 01:18:54

标签: python macos pytest tox

我正在运行一个基于Tox basic example的超级简单tox.ini文件和一个名为Automating Build, Test and Release Workflows with tox的演练视频。问题是,每当我运行tox命令时,都会收到一堆调用错误,并且出现“ ERROR:找不到文件:

tox.ini

# tox (https://tox.readthedocs.io/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
skipsdist = true
envlist = py36, py37, build
skip_missing_interpreters = true

[testenv]
whitelist_externals = *
passenv = *
deps = -rrequirements-test.txt
commands = {[testenv:unit]commands}

[travis]
python =
    3.6: py36
    3.7: py37, build

[testenv:unit]
deps = {[testenv]deps}
commands = pytest {posargs:--cov={envsitepackagesdir}/project_name {envsitepackagesdir}/project_name src/tests}

[testenv:test]
deps =
    {[testenv]deps}
    {[testenv:build]deps}
commands =
    {[testenv:unit]commands}
    {[testenv:build]commands}

[testenv:build]
skip_install = true
deps =
    wheel
commands =
    rm -rf dist build
    python -W ignore setup.py -q sdist bdist_wheel

;[testenv:release]
;deps =
;    {[testenv:build]deps}
;    twine
;commands =
;    {[testenv:build]commands}
;    twine upload dist/*
;

# From https://pytest-cov.readthedocs.io/en/latest/tox.html
[testenv:clean]
deps = coverage
skip_install = true
commands = coverage erase

[pytest]
addopts =
    -v -s
    --color=yes
    --cov
    --cov-append
    --cov-report=term-missing
    --cov-config=setup.cfg

[coverage:run]
omit =
    */tests/*
    */test_*
    */distutils/*
    */site-packages/*

[coverage:report]
show_missing = True

[flake8]
exclude = .tox

[report]
omit = */usr/*

CLI:

$ tox
py36 create: /path/to/my/project/python/project_namepy/.tox/py36
py36 installdeps: -rrequirements-test.txt
py36 installed: atomicwrites==1.3.0,attrs==19.1.0,bleach==3.1.0,certifi==2019.6.16,chardet==3.0.4,colorama==0.4.1,coverage==4.5.4,docutils==0.15.2,Faker==2.0.0,filelock==3.0.12,idna==2.8,importlib-metadata==0.19,more-itertools==7.2.0,packaging==19.1,pkginfo==1.5.0.1,pluggy==0.12.0,py==1.8.0,Pygments==2.4.2,pyparsing==2.4.2,pytest==5.0.1,pytest-cov==2.7.1,python-dateutil==2.8.0,readme-renderer==24.0,requests==2.22.0,requests-toolbelt==0.9.1,six==1.12.0,text-unidecode==1.2,toml==0.10.0,tox==3.13.2,tqdm==4.33.0,twine==1.13.0,urllib3==1.25.3,virtualenv==16.7.2,wcwidth==0.1.7,webencodings==0.5.1,zipp==0.5.2
py36 run-test-pre: PYTHONHASHSEED='2972258678'
py36 run-test: commands[0] | pytest --cov=/path/to/my/project/python/project_namepy/.tox/py36/lib/python3.6/site-packages/project_name /path/to/my/project/python/project_namepy/.tox/py36/lib/python3.6/site-packages/project_name src/tests
==================================================================================== test session starts ====================================================================================
platform darwin -- Python 3.6.5, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- /usr/local/Cellar/python/3.6.5/bin/python3.6
cachedir: .tox/py36/.pytest_cache
rootdir: /path/to/my/project/python/project_namepy, inifile: tox.ini
plugins: cov-2.7.1
collected 0 items                                                                                                                                                                           

=============================================================================== no tests ran in 0.02 seconds ================================================================================
ERROR: file not found: /path/to/my/project/python/project_namepy/.tox/py36/lib/python3.6/site-packages/project_name

ERROR: InvocationError for command /path/to/my/project/python/project_namepy/.tox/py36/bin/pytest --cov=/path/to/my/project/python/project_namepy/.tox/py36/lib/python3.6/site-packages/project_name /path/to/my/project/python/project_namepy/.tox/py36/lib/python3.6/site-packages/project_name src/tests (exited with code 4)
py37 create: /path/to/my/project/python/project_namepy/.tox/py37
py37 installdeps: -rrequirements-test.txt
py37 installed: atomicwrites==1.3.0,attrs==19.1.0,bleach==3.1.0,certifi==2019.6.16,chardet==3.0.4,colorama==0.4.1,coverage==4.5.4,docutils==0.15.2,Faker==2.0.0,filelock==3.0.12,idna==2.8,importlib-metadata==0.19,more-itertools==7.2.0,packaging==19.1,pkginfo==1.5.0.1,pluggy==0.12.0,py==1.8.0,Pygments==2.4.2,pyparsing==2.4.2,pytest==5.0.1,pytest-cov==2.7.1,python-dateutil==2.8.0,readme-renderer==24.0,requests==2.22.0,requests-toolbelt==0.9.1,six==1.12.0,text-unidecode==1.2,toml==0.10.0,tox==3.13.2,tqdm==4.33.0,twine==1.13.0,urllib3==1.25.3,virtualenv==16.7.2,wcwidth==0.1.7,webencodings==0.5.1,zipp==0.5.2
py37 run-test-pre: PYTHONHASHSEED='2972258678'
py37 run-test: commands[0] | pytest --cov=/path/to/my/project/python/project_namepy/.tox/py37/lib/python3.7/site-packages/project_name /path/to/my/project/python/project_namepy/.tox/py37/lib/python3.7/site-packages/project_name src/tests
==================================================================================== test session starts ====================================================================================
platform darwin -- Python 3.7.4, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- /usr/local/Cellar/python/3.6.5/bin/python3.6
cachedir: .tox/py37/.pytest_cache
rootdir: /path/to/my/project/python/project_namepy, inifile: tox.ini
plugins: cov-2.7.1
collected 0 items                                                                                                                                                                           

=============================================================================== no tests ran in 0.01 seconds ================================================================================
ERROR: file not found: /path/to/my/project/python/project_namepy/.tox/py37/lib/python3.7/site-packages/project_name

ERROR: InvocationError for command /path/to/my/project/python/project_namepy/.tox/py37/bin/pytest --cov=/path/to/my/project/python/project_namepy/.tox/py37/lib/python3.7/site-packages/project_name /path/to/my/project/python/project_namepy/.tox/py37/lib/python3.7/site-packages/project_name src/tests (exited with code 4)
build create: /path/to/my/project/python/project_namepy/.tox/build
build installdeps: wheel
build run-test-pre: PYTHONHASHSEED='2972258678'
build run-test: commands[0] | rm -rf dist build
build run-test: commands[1] | python -W ignore setup.py -q sdist bdist_wheel
__________________________________________________________________________________________ summary __________________________________________________________________________________________
ERROR:   py36: commands failed
ERROR:   py37: commands failed
  build: commands succeeded

1 个答案:

答案 0 :(得分:0)

aforementioned video期间,tox.ini设置中的第一行项目之一是编写与跳过sdist的创建有关的行,这被认为是“昂贵的” :

[tox]
skipsdist = true

事实证明,如果您的测试依赖于导入软件包,那么这是非常重要的一步(提示:他们几乎必须这样做。否则,他们要进行什么测试?)。视频的旁白(也是该项目的主要贡献者)确实提到以“开发”模式(pip install -e .)安装该软件包,但是却忽略了(或者我听错了)该软件包确实需要在某个时候安装。

将此值更改为skipsdist = false或仅删除该行即可完全解决问题。

相关问题