pytest的基础入门

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

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

pytest的fixture夹具

pytest的参数化

python 复制代码
#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的结合

python 复制代码
#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")
相关推荐
Be reborn2 小时前
用例不是孤立执行的:依赖、变量池与 storage_state 设计
python·自动化·pytest
小陈的进阶之路2 小时前
安集商城接口自动化项目架构介绍
python·自动化·pytest
测试员周周3 小时前
【Appium 系列】第08节-pytest 集成 — conftest.py 中的 fixture 与 hook
开发语言·人工智能·python·功能测试·appium·测试用例·pytest
Be reborn3 小时前
从一行 CSV 到一次浏览器操作:关键字驱动执行引擎设计
python·自动化·pytest
魔都吴所谓19 小时前
【开源LiteReport】告别 JDK 依赖 -- 用 LiteReport 为 pytest 项目打造轻量级测试报告
开源·pytest
旦莫3 天前
AI驱动的纯视觉自动化测试:知识库里应该积累什么知识内容
人工智能·python·测试开发·pytest·ai测试
夏至春来-美美3 天前
python 使用pytest的ini配置
开发语言·python·pytest
Be reborn3 天前
CSV + YAML 怎么描述测试:H5 SDK 自动化框架的数据模型设计
运维·自动化·pytest
Be reborn4 天前
用 Playwright 做自动化测试:如何验证网络请求并做断言
网络·python·自动化·pytest
lifewange6 天前
pytest 找不到文件?直接在 pytest.ini 配置根目录 + 路径(最简单方案)
开发语言·python·pytest