22-pytest-allure.step()测试步骤描述

目录

前言

代码示例

查看报告


前言

  • 场景测试中一般步骤较多,在自动化用例中,可以使用allure.step()添加步骤描述,便于理解和定位问题。

代码示例

# -*- coding: utf-8 -*-
# @Time    : 2021/11/27
# @Author  : 大海
# @File    : test_40.py

import os
import allure
import pytest

'''
场景:商品添加购物车,结算支付成功。
用例步骤:1.登陆  2.商品添加购物车  3.生成订单  4.支付成功
'''


@allure.step('前置操作:登录')
def login(username, password):
    """登录"""
    print(f"前置操作:登陆成功!{username}{password}")


@allure.step("step1:商品添加购物车")
def add_shopping_cart(goods_id):
    """添加购物车"""
    print(f"添加购物车{goods_id}")


@allure.step("step2:生成订单")
def create_order():
    """生成订单"""
    print("create_order:生成订单")


@allure.step("step3:支付")
def pay_money():
    """支付"""
    print("pay:支付!")


@pytest.fixture(scope="session")
def login_setup():
    login("大海", "123456")


@allure.feature("购物模块")
@allure.story("登录用户可购买商品")
@allure.title("登录用户,添加商品到购物车,下单支付成功。")
def test_add_goods_and_buy_(login_setup):
    """
    用例描述:
    前置:登陆
    用例步骤:1.添加购物车  2.生成订单  3.支付成功
    """

    # 商品添加购物车
    add_shopping_cart(goods_id=1018)

    # 生成订单
    create_order()

    # 支付
    pay_money()

    with allure.step("断言支付状态为true"):
        status = True
        assert status


if __name__ == '__main__':
    os.system('pytest -s test_40.py --alluredir ./report/allure_raw')

查看报告

  • allure  serve  报告路径

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱学习de测试小白

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值