一、环境搭建
- 安装:pip install -U pytest
- 官方参考文档:https://docs.pytest.org/en/latest/contents.html
二、应用举例
脚本1:test.py
#!/usr/bin/env python
#*-* coding:utf-8 -*-
import pytest
def add(a,b):
return a + b
def minus(a,b):
return a - b
#测试add方法
def test_add():
assert add(1,3) == 2
#测试minus方法
def test_minus():
assert minus(3,1) == 2
运行结果
脚本2:test.py
#!/usr/bin/env python
#*-* coding:utf-8 -*-
import pytest
def add(a,b):
return a + b
def minus(a,b):
return a - b
#测试add方法
def test_add():
assert add(1,3) == 4
#测试minus方法
def test_minus():
assert minus(3,1) == 2
运行结果