pytest tox.ini使用

tox简介:

tox是一个基于命令行驱动的Python自动化测试工具,基于virtualenv的使用。它既可以用于桌面上的手动调用测试,也可以用于持续集成框架(如Jenkins或Travis CI)中的连续测试。tox能够让我们在同一个Host上自定义出多套相互独立且隔离的python环境(tox是openstack社区最基本的测试工具,比如python程序的兼容性、UT等)。

tox.ini配置

[tox]
envlist = test_api
skipsdist=True
toxworkdir={toxinidir}/../var/.tox
indexserver = 
    default = https://pypi.doubanio.com/simple

[testenv]
changedir = {toxinidir}/..   
#安装依赖
deps = -r{toxinidir}/requirements.txt
setenv = 
    # 不生成_pycache_文件
    PYTHONDONTWRITEBYTECODE = 1
[testenv:test_api]
# 运行pytest并生成报告
commands = pytest \
    -vs {posargs:case/} --html=./var/report.html

部分参数解释

envlist 表示 tox 中配置的环境都有哪些,网上有很多比如py2,py3

toxworkdir 创建virtual 虚拟环境的路径

skipsdist = True tox默认会使用sdist构建包,对于测试来说没有必要,而且构建还会要求存在README、setup.py等文件,并且保证setup.py的格式符合要求等,所以跳过此步

changedir 执行命令时更改,以该目录当前目录

setenv 导入变量,跟exprot一样

posargs 参数变量 如果输入tox ,默认执行case目录,如果输入tox /test 则执行/test目录下的问题件,而不执行case目录下文件

安装使用

pip install tox

配置好文件后,可以tox 直接运行,也可以tox -e test_api
如果在其他目录下运行,则需要tox -c /test/tox.ini -c是指定配置文件的意思

requirements.txt

requests
pytest
pytest-html

参考资料

最重要的的还是官网
https://tox.readthedocs.io/en/latest/config.html

https://www.jianshu.com/p/20fdae9f8ab1
https://www.jianshu.com/p/645ec1c1c926
https://mathsyouth.github.io/2017/01/07/subunit-testr-tox
https://www.cnblogs.com/potato-chip/p/9094773.html
https://www.xuebuyuan.com/1859130.html
发布了34 篇原创文章 · 获赞 38 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/LANNY8588/article/details/90487029