python+requests接口自动化测试2--pytest框架编写测试用例

python+requests接口自动化测试2--pytest框架编写测试用例,第1张

概述使用pytest创建登录模块测试用例类importpytestdefget_timestamp():...defget_nonce():...defget_sign():...classBaseRequest:#请求方法类...classTest_Login(object):#测试用例类需继承objectdefsetup_class(self):print("用例

使用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框架编写测试用例全部内容,希望文章能够帮你解决python+requests接口自动化测试2--pytest框架编写测试用例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1159582.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存