1.将默认运行的方式设置为“pytest”
cmd中切换到当前的项目目录,进行安装
pip install -u pytest
或者下载镜像文件
pip install pytest -i https://pypi.mirrors.ustc.edu.cn/simple
2,template设置为pytest运行
3.测试是否利用pytest运行
import pytest
class Test_Run:
def aa(self,x):
return x+1
def test_answer(self):
assert self.aa(3)== 4
if __name__ == '__main__':
pytest.main(['-s','test_pytest.py'])
运行结果:
总结
1、首先创建 py 文件命名以 test_开始或者以_test 结尾
2、若是新建类,测试类需要以 Test_开头
3、测试用例(方法)需要以 test_开头