我正在阅读并试图理解一些在线图书馆,我遇到了以下情况:
- 没有 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
最佳答案
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
关于python - 如何使用 tox.ini 运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54873637/