初识pytest

安装pytest
pip install pytest
0
检查安装的pytest版本信息是否正确
pytest --version
0
创建测试
def func(x): return x+1 def test_answer(): assert func(3) == 5
0
运行多个测试
pytest会运行当前目录及子目录下的所有以test_开头或_test结尾的文件,文件匹配方式遵循Standard test discovery rules
判断是否发生了指定的异常
使用raises可以判断代码是否抛出异常
import pytest def f(): raise SystemExit(1) def test_mytest(): with pytest.raises(SystemExit): f()
使用quiet模式执行测试
0
查看官方文档
import requests help(requests)
0
 
posted @   乌醍  阅读(31)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
点击右上角即可分享
微信分享提示