以下内容纯属个人理解,如有不足,还请指正,转载请注明出处,喜欢请动动小指头点赞评论哦(▽)!
运行一个简单的用例:
#cd code/ch1/test_one.py
def test_passing():
assert (1, 2, 3) == (1, 2, 3)
运行结果及说明:
测试运行可能出现的结果总结(上图6、7运行结果列举)
类型(7) | 表示(6) | 说明 |
---|---|---|
PASSED | . | 测试通过 |
FAILED | F | 测试失败(fail或xpass与strict冲突造成的失败) |
SKIPPED | s | 测试未被执行 |
xfail | x | 预计测试失败,并且确实失败 |
XPASS | X | 预计测试失败,但实际上运行通过,不符合预期 |
ERROR | E | 测试用例之外的触发代码异常 |
示例:
import pytest
#测试通过
def test_passing():
assert (1, 2, 3) == (1, 2, 3)
#测试失败
def test_failing():
assert (1, 2, 3) == (3, 2, 1)
#跳过不执行
@pytest.mark.skip()
def test_skip():
assert (1, 2, 3) == (3, 2, 1)
#预期失败,确实失败
@pytest.mark.xfail()
def test_xfail():
assert (1, 2, 3) == (3, 2, 1)
#预期失败,但是结果pass
@pytest.mark.xfail()
def test_xpass():
assert (1, 2, 3) == (1, 2, 3)
运行结果: