#firtures通常用来对测试方法、测试函数、测试类和整个测试文件进行初始化或还原测试环境
# setup_module/teardown_module:在当前文件中,在所有测试用例执行之前与之后执行,只执行一次;
# setup_function/teardown_function:在每个测试函数之前与之后执行;
# setup/teardown:在每个测试函数之前与之后执行;

# 在当前文件下打开cmd窗口执行:pytest -s test_fixtures_01.py

#功能函数
def multiply(a,b):
return a * b

#===============Firtures=============
def setup_module(module):
print('setup_module------------>')

def teardown_module(module):
print('teardown_module--------->')

def setup_function(function):
print('setup_function---------->')

def teardown_function(function):
print('teardown_function-------->')

def setup():
print('setup---------->')

def teardown():
print('teardown------->')

#==========测试用例==========
def test_multiply_3_4():
print('test_numbers_3_4')
assert multiply(3,4) == 12

def test_multiply_a_3():
print('test_numbers_a_3')
assert multiply('a',3) == 'aaa'

#pytest 是支持使用测试类的,同样必须以Test开头,注意首字母大写。
# setup_class/teardown_class:在当前测试类的开始与结束时执行,只执行一次;
# setup_module/teardown_module:在每个测试方法开始与结束时执行;
# setup/teardown:在每个测试方法开始与结束时执行;

# 在当前文件下打开cmd窗口执行:pytest -s test_fixtures_02.py

#功能函数
def multiply(a,b):
return a * b

class TestMultiply:
#===============Firtures=============
@classmethod
def setup_class(cls):
print('setup_class------------>')

@classmethod
def teardown_class(cls):
print('teardown_class--------->')

def setup_module(self,module):
print('setup_module------------>')

def teardown_module(self,module):
print('teardown_module--------->')

def setup(self):
print('setup---------->')

def teardown(self):
print('teardown------->')

#==========测试用例==========
def test_multiply_5_6(self):
print('test_numbers_5_6')
assert multiply(5,6) == 30

def test_multiply_b_3(self):
print('test_numbers_b_3')
assert multiply('b',3) == 'bbb'

python + pytest 基本使用方法(Fixture)的更多相关文章

  1. python + pytest基本使用方法(拓展库)

    一.测试钩子配置文件 import pytest# conftest.py 是pytest特有的本地测试配置文件;# 既可以用来设置项目级别的Fixture,也可用来导入外部插件,还可以指定钩子函数# ...

  2. python + pytest基本使用方法(运行测试&测试报告)

    import pytest# 1.运行名称中包含某字符串的测试用例#名称中含add 的测试用例# 执行: pytest -k add test_assert.py# 2.减少测试的运行冗长# 执行: ...

  3. python + pytest基本使用方法(参数化)

    import pytestimport math#pytest 参数化#'base,exponent,expected'用来定义参数的名称.# 通过数组定义参数时,每一个元组都是一条测试用例使用的测试 ...

  4. python + pytest基本使用方法(断言)

    #pytest 的基本用法# 安装: pip install pytest#在当前目录下运行 : 输入 pytest# 1.断言#功能:用于计算a与b相加的和def add(a,b): return ...

  5. python pytest测试框架介绍二

    在介绍一中简单介绍了pytest的安装和简单使用,接下来我们就要实际了解pytest了 一.pytest的用例发现规则 pytest可以在不同的函数.包中发现用例,发现的规则如下 文件名以test_开 ...

  6. python:pytest中的setup和teardown

    原文:https://www.cnblogs.com/peiminer/p/9376352.html 之前我写的unittest的setup和teardown,还有setupClass和teardow ...

  7. Python+Pytest+Allure+Git+Jenkins接口自动化框架

    Python+Pytest+Allure+Git+Jenkins接口自动化框架 一.接口基础 接口测试是对系统和组件之间的接口进行测试,主要是效验数据的交换,传递和控制管理过程,以及相互逻辑依赖关系. ...

  8. Pytest(3)fixture的使用

    fixture的优势 Pytest的fixture相对于传统的xUnit的setup/teardown函数做了显著的改进: 命名方式灵活,不局限于 setup 和teardown 这几个命名 conf ...

  9. python+pytest接口自动化(11)-测试函数、测试类/测试方法的封装

    前言 在python+pytest 接口自动化系列中,我们之前的文章基本都没有将代码进行封装,但实际编写自动化测试脚本中,我们都需要将测试代码进行封装,才能被测试框架识别执行. 例如单个接口的请求代码 ...

随机推荐

  1. 嵌入式Linux设备驱动程序:在运行时读取驱动程序状态

    嵌入式Linux设备驱动程序:在运行时读取驱动程序状态 Embedded Linux device drivers: Reading driver state at runtime 在运行时了解驱动程 ...

  2. 尚硅谷Java——宋红康笔记【day19-day24】

    day19 测试Thread中的常用方法: start():启动当前线程:调用当前线程的run() run(): 通常需要重写Thread类中的此方法,将创建的线程要执行的操作声明在此方法中 curr ...

  3. PTA4-6题目集总结与归纳

    前言: 继上篇blog所写的几种日期的求法,这次是把那几种聚合起来,即日期类的聚合设计.除下这类,一种是图形继承设计的3种变化,还有一种是3次对正则表达式的应用.当然,作为一个菜鸟,还是无法写成大佬的 ...

  4. SqlServer数据库分区

    在最近的项目中,在尽可能优化了sql语句后,上层仍要求对数据库进行优化,因为考虑到系统上线后数据量会非常庞大,而且这些个表的数据都有明显的时间划分,于是就引入了数据库分区的概念.摘用百度百科的定义,数 ...

  5. Vue(5)计算属性computed

    前言 一般情况下属性都是放到data中的,但是有些属性可能是需要经过一些逻辑计算后才能得出来,那么我们可以把这类属性变成计算属性.比如以下: <div id="example" ...

  6. iOS-block本质是什么?

    一: block的原理是怎样的?本质是什么? block本质上也是一个OC对象,因为它的内部也有个isa指针 block是封装了函数调用以及函数调用环境的OC对象 接下来我们将通过底层源码来论证上诉两 ...

  7. R语言六种数据类型

    1 向量 1.1 定义向量 向量使用c来赋值,向量中不能混合不同类型的数据 x<-c(2,3,7,6,8)  数值型num y<-("one","two&qu ...

  8. R的基本使用

    一.R的安装 1.进入R的官网,https://cran.r-project.org/ 2.下载对应的版 Downloaad R for Windows > base > Download ...

  9. 每日三道面试题,通往自由的道路10——JMM篇

    茫茫人海千千万万,感谢这一秒你看到这里.希望我的面试题系列能对你的有所帮助!共勉! 愿你在未来的日子,保持热爱,奔赴山海! 每日三道面试题,成就更好自我 今天我们还是继续聊聊多线程的一些其他话题吧! ...

  10. 微信小程序 添加左边固定浮动框

    view: <!-- 悬浮框 --> <view class="v-fixed-title1"> <view class="v-fixed- ...