python - 如何使用 tox.ini 运行测试

标签 python pytest python-unittest python-3.7 tox

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

  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

最佳答案

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/

相关文章:

python - 无法从 pywinauto 导入 : ImportError: DLL load failed while importing win32ui: A dynamic link library (DLL) initialization routine failed

python - 自定义 pytest 收集测试

python - 如果 py.test 的另一个测试失败,我该如何跳过测试?

Python Mock - 如何像普通方法一样返回 MagicMock

python - python中aws lambda函数的自动化测试

python - 如何通过 Python 查询在 Elasticsearch 中的不同字段中找到相等的值?

python - 在自定义位置查找 conftest.py

python - 如何避免使用 pytest 从内部依赖项中获取 DeprecationWarning?

Python unittest 计算测试次数

python - 如何使用 travis-ci.org 测试需要键盘输入的项目?