您的位置:首页 > 汽车 > 时评 > 自己制作app软件_网页设计心得体会报告怎么写_友情链接你会回来感谢我_百度广告投放收费标准

自己制作app软件_网页设计心得体会报告怎么写_友情链接你会回来感谢我_百度广告投放收费标准

2024/12/23 1:10:23 来源:https://blog.csdn.net/tian_nx/article/details/144312900  浏览:    关键词:自己制作app软件_网页设计心得体会报告怎么写_友情链接你会回来感谢我_百度广告投放收费标准
自己制作app软件_网页设计心得体会报告怎么写_友情链接你会回来感谢我_百度广告投放收费标准

day91 pytest的setup,setdown详解(三)

学习日期:20241207

学习目标:pytest基础用法 -- pytest的setup,setdown详解(三)

学习笔记:

setup、teardown详解(三)
  • 类级 setup_class/teardown_class 只在类中前后运行一次(在类中)
import requests
import pytestclass TestMobile:@classmethoddef setup_class(cls):print("准备测试数据")@classmethoddef teardown_class(cls):print("清理测试数据")def test_mobile(self):print("测试手机归属地get请求")r = requests.get('https://api.binstd.com/shouji/query',params={"shouji": "13456755448", "appkey": "0c818521d38759e1"})assert r.status_code == 200result = r.json()assert result['status'] == 0assert result['msg'] == "ok"assert result['result']["shouji"] == "13456755448"assert result['result']["province"] == "浙江"assert result['result']["city"] == "杭州"assert result['result']["company"] == "中国移动"assert result['result']["cardtype"] is Noneassert result['result']["areacode"] == "0571"def test_mobile_post(self):print("测试手机归属地post请求")params = {"shouji": "13456755448","appkey": "0c818521d38759e1"}r = requests.post('https://api.binstd.com/shouji/query', params=params)assert r.status_code == 200result = r.json()assert result['status'] == 0assert result['msg'] == "ok"assert result['result']["shouji"] == "13456755448"assert result['result']["province"] == "浙江"assert result['result']["city"] == "杭州"assert result['result']["company"] == "中国移动"assert result['result']["cardtype"] is Noneassert result['result']["areacode"] == "0571"if __name__ == '__main__':pytest.main()
  • 方法级 setup_method/teardown_method 开始于方法始末(在类中)
import requests
import pytestclass TestMobile:@classmethoddef setup_method(cls):print("准备测试数据")@classmethoddef teardown_method(cls):print("清理测试数据")def test_mobile(self):print("测试手机归属地get请求")r = requests.get('https://api.binstd.com/shouji/query',params={"shouji": "13456755448", "appkey": "0c818521d38759e1"})assert r.status_code == 200result = r.json()assert result['status'] == 0assert result['msg'] == "ok"assert result['result']["shouji"] == "13456755448"assert result['result']["province"] == "浙江"assert result['result']["city"] == "杭州"assert result['result']["company"] == "中国移动"assert result['result']["cardtype"] is Noneassert result['result']["areacode"] == "0571"def test_mobile_post(self):print("测试手机归属地post请求")params = {"shouji": "13456755448","appkey": "0c818521d38759e1"}r = requests.post('https://api.binstd.com/shouji/query', params=params)assert r.status_code == 200result = r.json()assert result['status'] == 0assert result['msg'] == "ok"assert result['result']["shouji"] == "13456755448"assert result['result']["province"] == "浙江"assert result['result']["city"] == "杭州"assert result['result']["company"] == "中国移动"assert result['result']["cardtype"] is Noneassert result['result']["areacode"] == "0571"if __name__ == '__main__':pytest.main()
总结
  1. 类级 setup_class/teardown_class 只在类中前后运行一次(在类中)
  2. 方法级 setup_method/teardown_method 开始于方法始末(在类中)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com