如何使用 tox.ini 运行测试

may*_*may 4 python pytest tox python-unittest python-3.7

我正在在线阅读并试图理解一些图书馆,我遇到了以下内容:

  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}
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

如何运行此文件中的测试?该库称为相关: https: //github.com/genomoncology/lated/tree/master/tests

Ant*_*ile 8

tox它本身是一个环境管理器,可以为你运行一系列命令(想想make但它知道Python的东西)

通常,当存在 a 时,运行测试的最简单方法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
Run Code Online (Sandbox Code Playgroud)