使用多个fixture和fixture直接互相调用
使用多个fixture
如果用例需要用到多个fixture的返回数据,fixture也可以return一个元组、list或字典,然后从里面取出对应数据。
# test_fixture4.py
import pytest @pytest.fixture()
def user():
print("获取用户名")
a = "yoyo"
b = ""
return (a, b) def test_1(user):
u = user[]
p = user[]
print("测试账号:%s, 密码:%s" % (u, p))
assert u == "yoyo" if __name__ == "__main__":
pytest.main(["-s", "test_fixture4.py"])
当然也可以分开定义成多个fixture,然后test_用例传多个fixture参数
# test_fixture5.py
import pytest @pytest.fixture()
def user():
print("获取用户名")
a = "yoyo"
return a @pytest.fixture()
def psw():
print("获取密码")
b = ""
return b def test_1(user, psw):
'''传多个fixture'''
print("测试账号:%s, 密码:%s" % (user, psw))
assert user == "yoyo" if __name__ == "__main__":
pytest.main(["-s", "test_fixture5.py"])
fixture与fixture互相调用
fixture与fixture直接也能互相调用的
import pytest @pytest.fixture()
def first():
print("获取用户名")
a = "yoyo"
return a @pytest.fixture()
def sencond(first):
'''psw调用user fixture'''
a = first
b = ""
return (a, b) def test_1(sencond):
'''用例传fixture'''
print("测试账号:%s, 密码:%s" % (sencond[], sencond[])) assert sencond[] == "yoyo" if __name__ == "__main__":
pytest.main(["-s", "test_fixture6.py"])
使用多个fixture和fixture直接互相调用的更多相关文章
- pytest文档23-使用多个fixture和fixture直接互相调用
使用多个fixture 如果用例需要用到多个fixture的返回数据,fixture也可以return一个元组.list或字典,然后从里面取出对应数据. # test_fixture4.py impo ...
- fitnesse 中各类fit fixture的python实现
虽然网上都说slim效率很高,无奈找不到支持python的方法,继续用pyfit 1 Column Fixture 特点:行表格展现形式,一条测试用例对应一行数据 Wiki !define COMMA ...
- pytest进阶之fixture
前言 学pytest就不得不说fixture,fixture是pytest的精髓所在,就像unittest中的setup和teardown一样,如果不学fixture那么使用pytest和使用unit ...
- 单元测试之Fixture
声明: 作者:zhaojun 创建日期:2017-08-04 更新日期:2017-08-07 一.什么是Fixture,Fixture有什么作用,为什么需要使用Fixture # 下载 pip i ...
- Pytest高级进阶之Fixture
From: https://www.cnblogs.com/feiyi211/p/6626314.html 一. fixture介绍 fixture是pytest的一个闪光点,pytest要精通怎么能 ...
- pytest框架之fixture详细使用
本人之前写了一套基于unnitest框架的UI自动化框架,但是发现了pytest框架之后觉得unnitest太low,现在重头开始学pytest框架,一边学习一边记录,和大家分享,话不多说,那就先从p ...
- pytest.5.参数化的Fixture
From: http://www.testclass.net/pytest/parametrize_fixture/ 背景 继续上一节的测试需求,在上一节里,任何1条测试数据导致断言不通过后测试用例就 ...
- pytest.4.Fixture
From: http://www.testclass.net/pytest/fixture/ 我们可以简单的把Fixture理解为准备测试数据和初始化测试对象的阶段. 一般我们对测试数据和测试对象的管 ...
- Pytest - 进阶功能fixture
1. 概述 Pytest的fixture功能灵活好用,支持参数设置,便于进行多用例测试,简单便捷,颇有pythonic.如果要深入学习pytest,必学fixture. fixture函数的作用: 完 ...
随机推荐
- shell cat EOF 变量自动解析问题
使用如下shell安装node时,一直提示 command not found wget https://mirrors.huaweicloud.com/nodejs/latest-v8.x/node ...
- Python基础编程:字符编码、数据类型、列表
目录: python简介 字符编码介绍 数据类型 一.Python简介 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心 ...
- maven项目引入外部jar包
方式1:dependency 本地jar包 <dependency> <groupId>com.hope.cloud</groupId> <!--自定义--& ...
- C++最快获取像素值
HDC hdc, hdcTemp; RECT rect; BYTE* bitPointer; int x, y; int red, green, blue, alpha; while(true) { ...
- python之ORM
pymysql python操作数据库的基本步骤: 导入相应的python模块: 使用connect函数连接数据库,并返回一个connection对象: 通过connection对象的cursor方法 ...
- XXL-JOB原理--任务调度中心任务管理
XXL-JOB原理--任务调度中心任务管理 https://blog.csdn.net/qq924862077/article/details/82713758
- Spring MVC Theme(简单示例)
在渲染视图的spring-web中,配置them. 实现两个接口就可以使用: ResourceBundleThemeSource --> 用于确定要使用的主题的名字(theme name) S ...
- JPA的常用Annotation
http://www.blogjava.net/zJun/archive/2007/01/24/95747.html @transient 忽略该方法 一. @Entity:通过@Entity注解将一 ...
- JAVA记录 Spring 两大特性
1.IOC控制反转 Ioc—Inversion of Control,即“控制反转”,不是什么技术,而是一种设计思想.在Java开发中,Ioc意味着将你设计好的对象交给容器控制,而不是传统的在你的对象 ...
- [转] SSH两种登录方式(公私钥)解析
转自:https://www.cnblogs.com/hukey/p/6248468.html SSH登录方式主要分为两种: 1. 用户名密码验证方式 说明: (1) 当客户端发起ssh请求,服务器会 ...