跳转到主要内容

面向人类的Python测试

项目描述

pspec
=====

[![构建状态](https://travis-ci.org/bfirsh/pspec.png?branch=master)](https://travis-ci.org/bfirsh/pspec)

面向人类的Python测试,使用[Attest](http://packages.python.org/Attest/)构建。

测试不仅仅是让计算机检查代码是否运行正确。它们也可以由人类用来了解代码的功能。

pspec测试被设计成由人类解析。它们看起来有点像这样

```python
from pspec import describe, assert_raises
import random

with describe('random')
with describe('shuffle')
def it_does_not_lose_any_elements()
seq = range(10)
random.shuffle(seq)
seq.sort()
assert seq == range(10)

def it_raises_an_exception_for_an_immutable_sequence()
with assert_raises(TypeError)
random.shuffle((1, 2, 3))

with describe('choice')
def it_picks_an_element_that_is_in_the_sequence()
seq = range(10)
assert random.choice(seq) in seq
```

(与[内置unittest模块的类似示例](https://docs.pythonlang.cn/library/unittest.html#basic-example)进行比较。)

它们使用`pspec`命令运行

pspecrandomspec pip install -r requirements.txt
pythonsetup.pydevelop pspec spec

目标
-----

**注意**:pspec还处于初级阶段。不要期望它现在就有用。

这是我想要它做到的事情

- 美观的测试报告,带有彩色字符串差异。(类似于[Mocha的](http://visionmedia.github.com/mocha/#string diffs))
- 上下文、before/after钩子等。

它将简单、Pythonic,并使用最小魔法。


支持者