【问题标题】:Tox WARNING:test command found but not installed in testenvTox 警告:找到测试命令但未安装在 testenv 中
【发布时间】:2017-12-04 22:05:30
【问题描述】:

我正在为我的项目使用 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,覆盖。

但 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

【问题讨论】:

  • 如果您在需求中配置 pylint 和覆盖率,您会得到同样的错误吗?
  • 刚刚检查过,是的,它显示了相同的错误,但我得到了我想要的输出,但我无法理解为什么两者都有警告

标签: python unit-testing pylint tox


【解决方案1】:

您在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

【讨论】:

  • 不知道为什么 python 应该被列入白名单 - 它应该在 virtualenv 中!但我认为这是最好的答案,应该被接受 - @primer?
  • 就我而言,whitelist_externals = coverage 的白名单覆盖范围就足够了
  • @Duilio 取决于您在 virtualenv 中安装了哪些程序。如果您已安装 pylint,则无需将其列入白名单。
【解决方案2】:

按照错误使用的说明:

whitelist_externals = <your command>

例如我的外部命令是 curl 然后tox.ini 看起来像

[tox]
envlist = py3
isolated_build = True

[testenv]
whitelist_externals = curl
deps =
    pytest
    chispa
    pyspark
    requests
    requests-mock
commands =
    curl url/hadoop-aws-3.2.0.jar --output ../lib/jars/hadoop-aws-3.2.0.jar
    curl url/aws-sdk-java-2.jar --output ../lib/jars/aws-sdk-java-2.jar
    python3 -m pytest

【讨论】:

    【解决方案3】:

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

    这里,设置这个选项,也许,你通过了

    网站包=假(真|假) 如果您想创建还可以访问全局安装包的虚拟环境,请设置为 true。

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

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

    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.
    

    【讨论】:

      【解决方案4】:

      我不知道为什么,但为了解决,我不得不再次克隆我的 repo。 repo 重置不仅仅解决了完整的克隆问题。

      结帐this tox issue了解更多详情。

      【讨论】:

        【解决方案5】:

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

        【讨论】:

        • 警告:错误消失,但那是因为它不再找到定义testenv。将testenv 重命名为env 不是可行的方法!从那时起,您的测试将不再执行。
        【解决方案6】:

        我解决了这个问题。由于软件包依赖项已安装在您的默认虚拟环境中但未安装在 tox 环境中,因此会弹出错误。确保将运行 tox 所需的所有包都添加到您的 requirements.txt 中,包括 unittest 和 pytest

        【讨论】:

          猜你喜欢
          • 2021-10-25
          • 2020-11-04
          • 1970-01-01
          • 2019-05-11
          • 1970-01-01
          • 1970-01-01
          • 2011-04-30
          • 2017-03-31
          • 2015-07-09
          相关资源
          最近更新 更多