首页 > 其他分享 >pytest简易教程(28):pytest常用插件 - 重复测试(pytest-repeat)

pytest简易教程(28):pytest常用插件 - 重复测试(pytest-repeat)

时间:2024-02-23 22:49:27浏览次数:21  
标签:插件 repeat -- --- print pytest test

 

pytest简易教程汇总,详见https://www.cnblogs.com/uncleyong/p/17982846

使用场景

某功能不稳定,重复执行多次,以便复现问题

 

插件安装

安装:pip install pytest-repeat

 

使用方式一:命令行参数

参数:

  --count:重复运行次数,必填
  --repeat-scope:默认function,还可以是class、module、session,表示重复运行的维度,比如session,表示所有用例执行完一次,然后再执行第二次;选填

 

命令:

  pytest --count=count --repeat-scope=function

  或者:pytest --count count --repeat-scope function

 

参数也可以放配置文件中:

[pytest]
addopts = -vs --count 3 --repeat-scope function

 

示例:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 韧
# @wx :ren168632201
# @Blog :https://www.cnblogs.com/uncleyong/


# def test_d():
#     print("---test_d")
#
# def test_c():
#     print("---test_c")

def test_b():
    print("---test_b")

def test_a():
    print("---test_a")

  

--repeat-scope=function

运行结果:

结果:和上面一样,说明默认是function

 

--repeat-scope=module

运行结果:

 

--repeat-scope=class

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 韧
# @wx :ren168632201
# @Blog :https://www.cnblogs.com/uncleyong/


# def test_d():
#     print("---test_d")
#
# def test_c():
#     print("---test_c")

class Test1:
    def test_b(self):
        print("---test_b")
    def test_d(self):
        print("---test_d")
class Test2:
    def test_a(self):
        print("---test_a")
    def test_c(self):
        print("---test_c")

 

运行结果: 

 

--repeat-scope=session

运行结果:

 

 

使用方式二:修饰器

@pytest.mark.repeat(count)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 韧
# @wx :ren168632201
# @Blog :https://www.cnblogs.com/uncleyong/

import pytest

@pytest.mark.repeat(3)
def test_a():
    print("---test_a")
def test_b():
    print("---test_b")

  

运行结果:

 

标签:插件,repeat,--,---,print,pytest,test
From: https://www.cnblogs.com/uncleyong/p/18025590

相关文章

  • pytest简易教程(29):pytest常用插件 - 控制函数执行顺序(pytest-ordering)
     pytest简易教程汇总,详见:https://www.cnblogs.com/uncleyong/p/17982846 应用场景用例执行顺序,默认是按照从上到下的顺序进行执行的,详见:https://www.cnblogs.com/uncleyong/p/17956862如果想自定义执行顺序,也就是改变执行优先级,那么可以使用pytest-ordering 插件安装pi......
  • pytest简易教程(30):pytest常用插件 - 随机执行(pytest-random-order)
     pytest简易教程汇总,详见:https://www.cnblogs.com/uncleyong/p/17982846应用场景用来验证用例在随机(无序)执行时是否正常 插件安装pipinstallpytest-random-order 使用方式加参数:--random-order 示例#!/usr/bin/envpython#-*-coding:utf-8-*-#@Author......
  • pytest简易教程(27):pytest常用插件 - 失败重试(pytest-rerunfailures)
     pytest简易教程汇总,详见:https://www.cnblogs.com/uncleyong/p/17982846关于插件pytest有很多第三方插件:https://docs.pytest.org/en/latest/reference/plugin_list.html#plugin-list总共1300多个,一般最近1年内有更新的都是常用的。 使用场景针对运行不通过的用例运行重......
  • windows11系统下ppt突然打不开,报错“PowerPoint启动时提示上次启动失败是否启用安全模
    问题描述:windows11系统下ppt突然打不开,报错:PowerPoint启动时提示上次启动失败是否启用安全模式...ppt文件是正常的,我发到其他设备上是可以正常打开的。我把office卸载了用腾讯文档也无法打开ppt文件。点击用安全模式打开后无反应,即无错误提示也没有打开ppt。以上情况说明:......
  • 使用通义灵码插件提高开发效率
    目录概述功能特性安装准备工作VSCode安装IDEA安装使用指南续写代码代码注释写单元测试解释代码含义优化代码问答排查异常总结引用概述通义灵码是阿里云开发的一个编码助手,基于AI大模型,提供代码智能生成,智能问答等功能,旨在加快编码,提高开发效率。功能帮你续写代码帮你写代码......
  • 查询pytest --version报错 AttributeError: module ‘collections‘ has no attribute
     卸载pytest及关联的插件先查询一下pytest及对应关联的插件 pipuninstallcoloramaexceptiongroupiniconfigpackagingpluggytomliallure-pytestpytest-allure-adaptorpytest回车,每次都回复Y,同意卸载 再重新安装pytestpipinstallpytest-ihttp://pypi.douba......
  • vue3+vite 移动端适配postcss-pxtorem插件
    1、安装插件npmipostcss-pxtorem-D2、与package.json同级目录创建postcss.config.js文件module.exports={plugins:{autoprefixer:{overrideBrowserslist:["Android4.1","iOS7.1",......
  • 开发 Gradle 插件
    目录开发Gradle插件基础知识自定义插件扩展属性扩展Task开发Gradle插件基础知识Gradle中的Plugin是对完成指定功能的Task封装的体现,只要工程依赖了某个Plugin,就能执行该Plugin中所有的功能。插件的应用都是通过Project的apply方法完成的。插件分为二进制插......
  • M1 MacOS 配置C++环境时遇到的插件问题
    配置环境参照博客:https://www.cnblogs.com/BYGAO/p/15135609.html遇到问题:在Terminal--ConfigureDefaultBuildTasks--C/C++clang++这一步没有C/C++clang++选项。解决方法:shift+command+p打开搜索框,搜索SettingsSync:ShowSettings在IgnoredExtensions中打......
  • npm安装插件时遇到:npm ERR! code ERESOLVE或者 code ERESOLVE npm ERR! 错误
    1.问题我们在使用npminstall...时,遇到以下问题:npmERR!codeERESOLVEnpmERR!ERESOLVEcouldnotresolvenpmERR!npmERR!Whileresolving:@vue/[email protected]!Found:[email protected]!node_modules/eslint-plugin-vuenpm......