Bull's blog Bull's blog
首页
工作
  • 分类
  • 标签
  • 归档
关于

Bull

首页
工作
  • 分类
  • 标签
  • 归档
关于
  • 马上消费

  • 斗虫

    • 基础课件

      • python基础和条件语句
      • 基础数据类型_改
      • 函数
      • 1 函数练习
      • 32文件操作
      • 3 异常
      • 面向对象
      • 1面向对象案例-学生管理系统
      • 1Python基础练习题
      • 自动化测试理论
      • 2 接口测试基础
      • 3 requests
      • 4 代码
      • 5 简单封装
      • 1 pytest
      • 签名的设计
      • 接口case设计
      • 3 新建一个接口
      • x装饰器语法
      • httprunner2.x工具快速入门
      • httprunner3.x的简介
      • Flask框架
      • 了解任务
      • mock服务
      • UI自动化策略
      • PageObject模式
      • pytest参数化进阶
      • pytest框架生成报告
      • Yaml运用
      • 日志类模板
      • 持续集成
      • jdk配置
      • Linux基础
      • Jenkins主从测试任务
      • conda管理项目环境
      • 面试题-栈结构
      • 面试题-找众数
      • 正交测试法
      • 装饰器
      • 综合面试题_原版
    • RF

  • 天眼查

  • 某米

  • 工作经历
  • 斗虫
  • 基础课件
wangyang
2023-09-02

pytest参数化进阶

#encoding: utf-8
"""
indirect参数的功能是引用 方法
结合fixture来使用
"""
import pytest


test_username = ["user1", "user2"]
test_password = ["111111", "222222"]


@pytest.fixture(scope="module")
def test_user(request):
    username = request.param
    print("登录用户名: %s" % username)
    return username


@pytest.fixture(scope="module")
def test_psw(request):
    password = request.param
    print("登录密码:%s" % password)
    return password


@pytest.mark.parametrize("test_user", test_username, indirect=True)
@pytest.mark.parametrize("test_psw", test_password, indirect=True)
def test_login(test_user, test_psw):
    '''登录账户'''
    username = test_user
    password = test_psw
    print("登录账户为:%s : %s" % (username, password))
    assert 1 == 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# hook(钩子函数):在系统函数生效之前。
# 钩子函数就能够先执行,并且能拿到被“钩”的函数的所有参数、变量
# 可以进行加工处理,改变原有函数的功能

#目标是:把case名称变成中文字符
# 定义了pytest_collection_modifyitems,
# 对pytest收集参数产生了效果
def pytest_collection_modifyitems(items):
    for item in items:
        item.name = item.name.encode('utf-8').decode('unicode_escape')
        item._nodeid = item.nodeid.encode('utf-8').decode('unicode_escape')

def pytest_configure(config):
    config.addinivalue_line('markers','P0')#P0是在最高级别,所有情况都要回归
    config.addinivalue_line('markers','P1')#P1在版本上线前回归
    config.addinivalue_line('markers','P2')#P2要求在大版本上线前,进行回归
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#python自动化#自动化入门
上次更新: 2023/09/05, 02:16:11
PageObject模式
pytest框架生成报告

← PageObject模式 pytest框架生成报告→

最近更新
01
30.快速实现接口重构测试---deepdiff库使用
09-21
02
概述
09-07
03
概述
09-07
更多文章>
Theme by Vdoing | Copyright © 2018-2025 Evan Xu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式