安装

pip install tox

tox 使用

tox 包含一个tox.ini 文件,此文件可以自动,或者手工编写

  • tox.ini 文件格式
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py27,py36
[testenv]
# install pytest in the virtualenv where commands will be executed
deps = pytest
commands =
    # NOTE: you can run any command line tool here - not just tests
    pytest
  • 自动生成的方法

    使用 tox-quickstart

参考如下:

Welcome to the tox 3.12.1 quickstart utility.
This utility will ask you a few questions and then generate a simple configuration file to help get you started using tox.
Please enter values for the following settings (just press Enter to accept a default value, if one is given in brackets).
What Python versions do you want to test against?
            [1] py36
            [2] py27, py36
            [3] (All versions) py27, py34, py35, py36, pypy, jython
            [4] Choose each one-by-one
> Enter the number of your choice [3]: 
What command should be used to test your project? Examples: - pytest
"
            - python -m unittest discover
            - python setup.py test
            - trial package.module
> Type the command to run your tests [pytest]: 
What extra dependencies do your tests have?
default dependencies are: ['pytest']
> Comma-separated list of dependencies: hashids
Finished: ./tox.ini has been created. For information on this file, see https://tox.readthedocs.io/en/latest/config.html
Execute `tox` to test your project.

效果

# tox (https://tox.readthedocs.io/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
[tox]
envlist = py27, py34, py35, py37
[testenv]
deps =
    hashids
    pytest
commands =
    pytest

项目配置

  • 项目结构

    因为系统只安装了python2.7 以及3.7 所以tox.ini 稍有修改

├── README.md
├── myids
│ └── __init__.py
├── setup.py
└── tox.ini
  • 项目说明
    myids/init.py
 
from hashids import Hashids
hashids = Hashids()
def generateID():
    hashid = hashids.encode(123, 456, 789)
    print(hashid)
if __name__ == '__main__':
    generateID()

setup.py

import setuptools
with open("README.md", "r") as fh:
    long_description = fh.read()
setuptools.setup(
    name="myids",
    version="0.0.3",
    author="dalongrong",
    author_email="1141591465@qq.com",
    description="myids package",
    long_description=long_description,
    install_requires=['hashids'],
    long_description_content_type="text/markdown",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
)
 

tox.ini

# tox (https://tox.readthedocs.io/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
[tox]
envlist = py27,py37
[testenv]
deps =
    hashids
    pytest
commands =
    pytest

使用

  • 命令
tox
  • 效果

    因为我没有添加测试,所以会有一些关于测试的错误提示

GLOB sdist-make: /Users/dalong/mylearning/tox-projects/setup.py
py27 inst-nodeps: /Users/dalong/mylearning/tox-projects/.tox/.tmp/package/1/myids-0.0.3.zip
py27 installed: atomicwrites==1.3.0,attrs==19.1.0,configparser==3.7.4,contextlib2==0.5.5,funcsigs==1.0.2,hashids==1.2.0,importlib-metadata==
0.17,more-itertools==5.0.0,myids==0.0.3,packaging==19.0,pathlib2==2.3.3,pluggy==0.12.0,py==1.8.0,pyparsing==2.4.0,pytest==4.6.2,scandir==1.1
0.0,six==1.12.0,wcwidth==0.1.7,zipp==0.5.1
py27 run-test-pre: PYTHONHASHSEED='1001942139'
py27 run-test: commands[0] | pytest
=========================================================== test session starts ============================================================
platform darwin -- Python 2.7.15, pytest-4.6.2, py-1.8.0, pluggy-0.12.0
cachedir: .tox/py27/.pytest_cache
rootdir: /Users/dalong/mylearning/tox-projects
collected 0 items                                                                                                                          
======================================================= no tests ran in 0.01 seconds =======================================================
ERROR: InvocationError for command /Users/dalong/mylearning/tox-projects/.tox/py27/bin/pytest (exited with code 5)
py37 inst-nodeps: /Users/dalong/mylearning/tox-projects/.tox/.tmp/package/1/myids-0.0.3.zip
py37 installed: atomicwrites==1.3.0,attrs==19.1.0,hashids==1.2.0,importlib-metadata==0.17,more-itertools==7.0.0,myids==0.0.3,packaging==19.0
,pluggy==0.12.0,py==1.8.0,pyparsing==2.4.0,pytest==4.6.2,six==1.12.0,wcwidth==0.1.7,zipp==0.5.1
py37 run-test-pre: PYTHONHASHSEED='1001942139'
py37 run-test: commands[0] | pytest
=========================================================== test session starts ============================================================
platform darwin -- Python 3.7.3, pytest-4.6.2, py-1.8.0, pluggy-0.12.0
cachedir: .tox/py37/.pytest_cache
rootdir: /Users/dalong/mylearning/tox-projects
collected 0 items                                                                                                                          
======================================================= no tests ran in 0.01 seconds =======================================================
ERROR: InvocationError for command /Users/dalong/mylearning/tox-projects/.tox/py37/bin/pytest (exited with code 5)
_________________________________________________________________ summary __________________________________________________________________
ERROR: py27: commands failed
ERROR: py37: commands failed

说明

tox 工具还是很方便的,可以简化我们测试以及构建

参考资料

https://tox.readthedocs.io/en/latest/
https://github.com/tox-dev/tox

tox 试用的更多相关文章

  1. openstack单元測试用组件一览

    声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 内容系本人学习.研究和总结,如有雷同,实属荣幸! 组件一览 hacking 一 ...

  2. SharePoint Online 申请试用链接地址

    SharePoint Online 申请试用链接地址: https://products.office.com/en-us/business/compare-office-365-for-busine ...

  3. 小众Tox——大众的“去中心化”聊天软件

    ★Tox是什么 一个反窥探的开源项目:一种基于DHT(BitTorrent)技术的即时通讯协议:一个为安全而生的加密通讯系统 .美国棱镜计划曝光后,一个名为 irungentoo 的牛人于17天后的2 ...

  4. 活动助手Beta用户试用报告

    用户试用报告 1.面向参与者用户 1.1 日常参加各类学习(水综测)活动中,有没有遇到以下问题: (1) 信息来源混乱,不知道靠不靠谱 (2) 每次报名都要重新填写自己的学号手机号,有时候填错了就没综 ...

  5. 创建WP8试用应用

    参考资料: 创建 Windows Phone 的试用应用 如何在 Windows Phone 应用中实现试用体验 Windows Phone 7 开发 31 日谈——第23日:提供试用版应用程序 对资 ...

  6. 达梦7的试用 与SQLSERVER的简单技术对比

    达梦7的试用 与SQLSERVER的简单技术对比 达梦数据库公司推出了他们的数据库服务管理平台,可以在该平台使用达梦数据库而无须安装达梦7数据库 地址:http://online.dameng.com ...

  7. Beta版本——用户试用与调研报告

    1 引言 1.1 系统概述 ​ 毕设导师智能分配系统是一个用来简化传统手工匹配繁琐操作的系统.本系统将学生报志愿.系负责人收集整理数据.相关人员进行手工分配.反馈选择结果等繁琐的操作转移到线上.把毕设 ...

  8. 【记录】尝试用android-logging-log4j去实现log输出内容到sd卡中的文件的功能

    [背景] 折腾: [记录]给Android中添加log日志输出到文件 期间,已经试了: [记录]尝试用android中microlog4android实现log输出到文件的功能 但是不好用. 然后就是 ...

  9. 代码阅读分析工具Understand 2.0试用

    Understand 2.0是一款源代码阅读分析软件,功能强大.试用过一段时间后,感觉相当不错,确实可以大大提高代码阅读效率.由于Understand功能十分强大,本文不可能详尽地介绍它的所有功能,所 ...

随机推荐

  1. Ambari深入学习(II)-实现细节

    在第一节中,我们简单讲了一下Ambari的系统架构.我们这一节主要分析Ambari的源代码,总览Ambari的具体实现方式及其工作细节. 一.Ambari-Server启动 Ambari-Server ...

  2. spring Boot 学习(四、Spring Boot与任务)

    一.异步任务 在Java应用中,绝大多数情况下都是通过同步的方式来实现交互处理的:但是在 处理与第三方系统交互的时候,容易造成响应迟缓的情况,之前大部分都是使用 多线程来完成此类任务,其实,在Spri ...

  3. C# vb .net实现邮戳效果滤镜

    在.net中,如何简单快捷地实现Photoshop滤镜组中的邮戳效果呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第一步 ...

  4. [golang]按图片中心旋转后的新图左顶点和原图左顶点的偏移量计算

    1 前言 略,作为记录使用 2 代码 /** * @Author: FB * @Description: * @File: RotateSample.go * @Version: 1.0.0 * @D ...

  5. PS利用蒙版抠图

    扣图除了用锁套工具外,用蒙版时一个比较快的方法. 前期准备 首先准备一个PS CS6和一个神仙姐姐,一定要先Ctrl+J复制一份图层(不然待会神仙姐姐就找不到了). 使用色阶及反相获取轮廓 使用色阶使 ...

  6. fileinput 配置项大全,从源码中翻出了很多属性,没那么多时间一一验证,特发出来给大家参考参考

    fileinput 配置项大全,从源码中翻出了很多属性,没那么多时间一一验证,特发出来给大家参考参考 fileinput 配置项大全 option 属性名 属性类型 描述说明 默认值 language ...

  7. Flask框架 请求与响应 & 模板语法

    目录 Flask框架 请求与响应 & 模板语法 简单了解Flask框架 Flask 框架 与 Django 框架对比 简单使用Flask提供服务 Flask 中的 Response(响应) F ...

  8. Spring的核心机制:依赖注入

    依赖注入的概念 当一个对象要调用另一个对象时,一般是new一个被调用的对象,示例: class  A{ private B b=new B(); public  void  test(){ b.say ...

  9. PHP实现财务审核通过后返现金额到客户

    应用场景: 有这么一个返现的系统,当前端客户发起提现的时候,后端就要通过审核这笔返现订单,才可以返现到客户的账号里. 来看看下面的截图 这里的业务场景就是经过两轮审核:销售审核,财务审核都通过后,后端 ...

  10. SQL Text Literals 文本

    Text Literals 文本 Use the text literal notation to specify values whenever string appears in the synt ...