当前位置: 首页 > article >正文

pytest的基础入门

pytest判断用例的成功或者失败

pytest识别用例失败时会报AssertionError或者xxxError错误,当捕获异常时pytest无法识别到失败的用例

pytest的fixture夹具

pytest的参数化

#coding:utf-8
import pytest

from PythonProject.pytest_test.funcs.guess_point import get_the_number_of_points
test_datas = [6,9,10,4,5]
class TestGuessPoint:
    @classmethod
    def setup_class(cls):
        print("测试类当中,第一个执行用例之前,做的准备工作代码...")
    @classmethod
    def teardown_class(cls):
        print("测试类当中所有的用例执行完毕之后做的清理干工作...")
    # def setup_method(self):
    #     print("===每一个测试用例之前都要执行===")
    # def teardown_method(self):
    #     print("===每一个测试用例之后都要执行===")
    @pytest.mark.parametrize("case",test_datas)
    def test_guess(self,case):
        point = get_the_number_of_points()
        assert case == point

pytest和allure的结合

#coding:utf-8
import pytest
import allure
from PythonProject.pytest_test.funcs.log_fuc import login
all_datas=[
    {"user":"1234","passwd":"123456","check":"恭喜登录成功"},
    {"user":"None123","passwd":"False12345","check":"用户名或密码不正确"},
    {"user":"123","passwd":"123456","check":"用户名长度小于4"},
    {"user":"12345","passwd":"12345","check":"密码长度小于6"}
]
# @pytest.mark.usefixtures("class_fix")
class TestLogin:
    # def setup_method(self):
    #     print("每一个测试用例之前执行")
    # def teardown_method(self):
    #     print("每一个测试用例都要执行的后置")

    @pytest.mark.parametrize("casep",all_datas)
    @allure.description("登录模块测试,后端管理员用户角色---")
    @allure.issue("https://www.baidu.com","bug地址")
    @allure.testcase("https://www.baidu.com","xx平台测试用例地址")
    def test_login(self,casep):
        res = login(casep.get("user"),casep.get("passwd"))
        assert res == casep.get("check")


http://www.kler.cn/news/340583.html

相关文章:

  • 1-Lipschitz函数
  • IDEA下“File is read-only”可能原因及“找不到或无法加载主类”问题的解决
  • ROS2入门篇——ROS2第一个节点
  • Chromium 如何定义一个chrome.settingsPrivate接口给前端调用c++
  • BUU刷题-Pwn-shanghai2018_baby_arm(ARM_ROP_csu_init,ARM架构入门)
  • React常见优化问题
  • 如何编写测试用例
  • python 实现algorithm topo卡恩拓扑算法
  • C/C++复习(一)
  • 深入了解 TypeScript 现代 JavaScript 的超集
  • sqli-labs less-14post报错注入updatexml
  • gbase8s数据库实现黑白名单的几种方案
  • 网络受限情况下安装openpyxl模块提示缺少Jdcal,et_xmlfile
  • 2-110 基于matlab的双字典交叉稀疏表示的SAR图像变化检测
  • 运行CtsVerifier.apk报错
  • mybatis自定义类型处理器
  • 【2024】前端学习笔记13-JavaScript修改网页样式
  • Java、PHP、ASP、JSP、Kotlin、.NET、Go
  • 蓝牙定位的MATLAB程序※平面上的定位,可自适应蓝牙基站的数量(附下载链接)
  • Java中变量