1、环境搭建html
- 安装:pip install -U pytest
- 官方参考文档:https://docs.pytest.org/en/latest/contents.html
2、应用举例python
脚本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
运行结果code
脚本2:test.pyhtm
#!/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
运行结果blog