Tox警告:找到测试命令但未在testenv中安装

时间:2017-12-04 22:05:30

标签: python unit-testing pylint tox

嘿伙计们,所以我基本上都在为我的项目使用tox。

这是我的tox.ini文件

[tox]
envlist =
    py27,
    lint,
    coverage

skipsdist = True

[testenv:py27]
deps = -rrequirements.txt
commands = python -m unittest discover -s ./tests

[testenv:coverage]
commands =
    coverage run --source=tests -m unittest discover -s tests/
    coverage html
    coverage report


[testenv:lint]
commands = pylint ./foo

每当我运行tox时,一切都在执行,基本上是linting,coverage。

但Tox正在显示所有内容的警告。

WARNING:test command found but not installed in testenv
Maybe you forgot to specify a dependency? See also the whitelist_externals envconfig setting.

一切都成功但仍然显示警告和错误

任何人都可以告诉我我做错了什么。

我的requirements.txt文件

requests==2.18.4
JsonForm==0.0.2
jsonify==0.5
jsonschema==2.6.0
JsonSir==0.0.2
python-dateutil==1.5
DateTime==4.2
urllib3==1.22
contextlib2==0.5.5
mock==2.0.0
patch==1.16

4 个答案:

答案 0 :(得分:9)

您在commands中使用的程序必须安装在tox'虚拟环境或白名单:

[tox]
envlist =
    py27,
    lint,
    coverage

skipsdist = True

[testenv:py27]
deps = -rrequirements.txt
whitelist_externals = python
commands = python -m unittest discover -s ./tests

[testenv:coverage]
whitelist_externals = coverage
commands =
    coverage run --source=tests -m unittest discover -s tests/
    coverage html
    coverage report


[testenv:lint]
whitelist_externals = pylint
commands = pylint ./foo

答案 1 :(得分:1)

https://tox.readthedocs.io/en/latest/config.html

在这里,设置此选项,也许,您通过

  

sitepackages = false(true | false)   如果要创建还可以访问全局安装的软件包的虚拟环境,请设置为true。

警告 如果还全局安装了命令行工具,则必须确保通过使用python -m(如果工具支持)或{envbindir} /使用已安装在virtualenv中的工具。

如果您忘记这样做,将会收到如下警告:

WARNING: test command found but not installed in testenv
    cmd: /path/to/parent/interpreter/bin/<some command>
    env: /foo/bar/.tox/python
Maybe you forgot to specify a dependency? See also the whitelist_externals envconfig setting.

答案 2 :(得分:1)

问题很旧,但答案不适用于我的情况。就我而言,将[testenv]更改为[env]后,它就可以工作了。这是因为我的Python虚拟环境被命名为“ env”。

答案 3 :(得分:1)

我不知道为什么,但是要解决这个问题,我不得不重新克隆我的仓库。回购重置不仅只能解决完整克隆问题。

结帐this tox issue以获得更多详细信息。