【问题标题】:How to run tests with tox.ini如何使用 tox.ini 运行测试
【发布时间】:2019-07-19 07:05:57
【问题描述】:

我正在阅读并尝试了解一些在线图书馆,我遇到了以下情况:

  1. 没有 pytest 或 unitest 的测试

我在网上阅读,发现一个 tox.ini 文件,如下所示:

[tox]
envlist =
    py27
    py35
    py36
    py37
    flake8

[testenv:flake8]
basepython = python
deps = flake8
commands = flake8 related

[testenv]
setenv =
    PYTHONPATH = {toxinidir}:{toxinidir}/related

deps =
    -r{toxinidir}/dev-requirements.txt

commands =
    pip install -U pip
    py.test --basetemp={envtmpdir}

我仍然无法让它运行。我做了以下事情:

pip install -U pip
py.test --basetemp={envtmpdir}
py.tests --basetemp={py37}

usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --mccabe --pep8 --flake8
  inifile: /home/tmhdev/Documents/related/pytest.ini
  rootdir: /home/tmhdev/Documents/related

如何运行此文件中的测试? 库调用相关:https://github.com/genomoncology/related/tree/master/tests

【问题讨论】:

  • 那些未知选项在您的pytest.ini 中。删除它们,这些是flake8 的选项,而不是pytest

标签: python pytest python-unittest python-3.7 tox


【解决方案1】:

tox itself is an environment manager 可以为你运行一系列命令(想像 make 但它知道 python 的东西)

当有 tox.ini 时,运行测试的最简单方法通常是调用 tox 本身(您可以使用 pip install tox 安装它)

如果你想大致重现 tox 在幕后所做的事情(比如上面的 tox -e py37),你需要创建一个 virtualenv 然后调用测试。

# environment setup
virtualenv -p python3.7 .tox/py37
. .tox/py37/bin/activate
.tox/py37/bin/pip install -r dev-requirements.txt
export PYTHONPATH=$PWD:$PWD/related

# testenv `commands`
pip install -U pip
py.test --basetemp=.tox/py37/tmp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 2021-04-23
    • 2014-01-09
    • 2015-03-17
    • 2012-02-11
    • 2021-01-30
    相关资源
    最近更新 更多