python+requests接口自动化测试2--pytest框架编写测试用例
2021/6/22 14:27:02
本文主要是介绍python+requests接口自动化测试2--pytest框架编写测试用例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
使用pytest创建登录模块测试用例类
import pytest def get_timestamp(): ... def get_nonce(): ... def get_sign(): ...
class BaseRequest: # 请求方法类 ... class Test_Login(object): # 测试用例类需继承object def setup_class(self): print("用例执行前执行,主要用于初始化工作") def teardown_class(self): print("用例执行结束后执行") # 登录成功 def test_userLogin_ok(self): # 测试用例 url = "https://xxx/login/password" nonce = get_nonce() timestamp = get_timestamp() params = {"username": "admin", "password": "4297f44b13955235245b2497399d7a93"} sign = get_sign(params, ....) header = {"Content-Type": "application/json", "client": "xxx", "sign": sign, "timestamp": timestamp, "nonce": nonce} br = BaseRequest(url) re = br.sureMethod(header, "post", params) print(re.json()) # 用户名错误 def test_userLogin_fail(self):
url = "https://xxx/login/password" nonce = get_nonce() timestamp = get_timestamp() params = {"username": "admin11", "password": "4297f44b13955235245b2497399d7a92"} sign = get_sign(params, key, "", timestamp, nonce) header = {"Content-Type": "application/json", "client": "xxx", "sign": sign, "timestamp": timestamp, "nonce": nonce} br = BaseRequest(url) re = br.sureMethod(header, "post", params) print(re.json())
if __name__ == '__main__': pytest.main(['-sv', "api.py"])
这篇关于python+requests接口自动化测试2--pytest框架编写测试用例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-01Python编程基础知识
- 2024-11-01Python编程基础
- 2024-10-31Python基础入门:理解变量与数据类型
- 2024-10-30Python股票自动化交易资料详解与实战指南
- 2024-10-30Python入行:新手必读的Python编程入门指南
- 2024-10-30Python入行:初学者必备的编程指南
- 2024-10-30Python编程入门指南
- 2024-10-30Python量化交易学习:新手入门指南
- 2024-10-30Python股票自动化交易实战入门教程
- 2024-10-29Python股票自动化交易教程:新手入门指南