@songying
2018-06-30T14:36:21.000000Z
字数 868
阅读 1247
单元测试
pip install tox
Tox 是标准的 virtualenv 管理器和命令行测试工具,它创造一个隔离的 Python 沙箱环境,根据配置下载安装依赖包,然后执行测试用例。
tox.ini
文件编写
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py27,py36
[testenv]
deps=pytest # or 'nose' or ...
commands=pytest # or 'nosetests' or ...
platform = linux2|darwin # 指定平台, 与sys.platform
whitelist_externals = make
/bin/bash # use tools not contained in your virtualenv such as make, bash or others
tox #
tox -e py36 # py27, py3, py34, py35, py36, py37
tox.ini # see below for content
setup.py # a classic distutils/setuptools setup.py file
tests # the directory containing tests
tox.ini
中的文件如下:
[tox]
envlist = py35,py36
[testenv]
changedir=tests
deps = pytest # PYPI package providing pytest
commands= pytest --basetemp={envtmpdir} \ # pytest tempdir setting
{posargs} # substitute with tox' positional arguments