tox包

官方文档

https://tox.readthedocs.io/en/latest/example/basic.html

官方提供的一个简单的tox.ini/默认环境

[tox]
envlist = py27,py36
[testenv]
deps = pytest
commands = pytest

运行

>>>: tox  # 同时创建两个virtualenv环境,并打包安装到环境中
>>>: tox -e py36  # 限制只在py3.6环境中运行

大致配置分析

[tox]
minversion = 2.0 # 指定最小版本
envlist = py27,py36  # 指定要使用的环境列表
[testenv]  # 测试环境
skipsdist = True  # 跳过打包环节
#[testenv:py36]  # 指定具体版本的测试环境
basepython = python3.7  # 配置python解释器版本
deps = pytest
# deps = -rrequirements.txt   # 读取requirements.txt文件中所有的安装包
# deps = {toxinidir}/requirements.txt # tox.ini所在目录作为当前目录来执行安装
# deps = django22: Django>=2.2,<2.3  # 指定具体的版本安装
setenv =  # 设置环境变量
  PIP_INDEX_URL = https://pypi.my-alternative-index.org # 指定源
commands = pytest # 运行命令
commands = - coverage html  # -表示忽略命令
commands = pytest --basetemp="{envtmpdir}" {posargs}  # 更改pytest tempdir并从命令行添加posargs
allowlist_externals = make  # 使用不包含在virtualenv工具的命令解析器
# allowlist_externals = /bin/bash

基本目录结构

  - tox.ini
  - setup.py
  - tests
posted @ 2021-04-15 14:09  我在路上回头看  阅读(159)  评论(0编辑  收藏  举报