简单的unittest runner: green
乙醇 创建于 8 months 之前
最后更新: less than a minute 之前
阅读数: 485
首先来个截图。
green是unittest 众多runner中功能比较丰富的一个。
官方的featrue介绍如下:
Clean - Low redundancy in output. Result statistics for each test is vertically aligned.
Colorful - Terminal output makes good use of color when the terminal supports it.
Fast - Tests run in independent processes. (One per processor by default. Does not play nicely with gevent)
Powerful - Multi-target + auto-discovery.
Traditional - Use the normal unittest classes and methods for your unit tests.
Descriptive - Multiple verbosity levels, from just dots to full docstring output.
Convenient - Bash-completion and ZSH-completion of options and test targets.
Thorough - Built-in integration with coverage.
Embedded - Can be run with a setup command without in-site installation.
Modern - Supports Python 3.5+. Additionally, PyPy is supported on a best-effort basis.
Portable - macOS, Linux, and BSDs are fully supported. Windows is supported on a best-effort basis.
Living - This project grows and changes. See the changelog
简单来说,green的一些优势有:
- 简单高效
- 命令行输出支持各种高亮
- 一直在维护
- 支持python3
- 集成了代码覆盖率
安装
pip install green
简单使用
我们可以用官方的例子来简单玩一下。
git clone https://github.com/CleanCut/green.git
cd green/example/proj
green -vvv --run-coverage
运行结果
Green 3.0.0, Coverage 4.5.4, Python 2.7.15
proj.test.test_foo
TestAnswer
. answer() returns 42
. answer() returns an integer
TestSchool
. test_age
. test_food
Name Stmts Miss Cover Missing
--------------------------------------------------
__init__.py 0 0 100%
foo.py 7 0 100%
subpkg/__init__.py 0 0 100%
--------------------------------------------------
TOTAL 7 0 100%
Ran 4 tests in 0.123s using 8 processes
OK (passes=4)
因为我是纯文本贴出来的,所以没能体现出高亮的效果。大家可以自己试着运行一下,在mac上还是很好看的。windows上表现怎么样还不是很清楚。
适用场景
- green支持跟django集成,可以替换django的默认testrunner
- green支持的配置很多,可以敲
green -h
来看,可以作为自己测试项目的基础框架,从而实现更多功能