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")
相关推荐
小熊出擊1 天前
【pytest】finalizer 执行顺序:FILO 原则
python·测试工具·单元测试·pytest
小熊出擊2 天前
【pytest】使用 marker 向 fixture 传递数据
python·pytest
wa的一声哭了2 天前
Deep Learning Optimizer | Adam、AdamW
人工智能·深度学习·神经网络·机器学习·自然语言处理·transformer·pytest
专职4 天前
pytest生成测试用例,allure生成测试报告
测试用例·pytest
小丁爱养花7 天前
接口自动化测试 - pytest [1]
python·自动化·pytest
向上的车轮8 天前
如何用AI工具开发一个轻量化CRM系统(七):AI生成pytest测试脚本
pytest
慌糖9 天前
自动化接口框架搭建分享-pytest第三部分
运维·自动化·pytest
Script kid9 天前
Pytest框架速成
数据库·pytest
小熊出擊9 天前
[pytest] 一文掌握 fixture 的作用域(scope)机制
python·功能测试·单元测试·自动化·pytest
小熊出擊10 天前
[pytest] autouse 参数:自动使用fixture
python·测试工具·单元测试·自动化·pytest