pytest运行_python压测

pytest运行_python压测前言pytest运行完用例之后会生成一个.pytest_cache的缓存文件夹,用于记录用例的ids和上一次失败的用例。方便我们在运行用例的时候加上–lf和–ff参数,快速运行上一

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

前言

pytest 运行完用例之后会生成一个 .pytest_cache 的缓存文件夹,用于记录用例的ids和上一次失败的用例。
方便我们在运行用例的时候加上–lf 和 –ff 参数,快速运行上一次失败的用例。
–lf, –last-failed 只重新运行上次运行失败的用例(或如果没有失败的话会全部跑)
–ff, –failed-first 运行所有测试,但首先运行上次运行失败的测试(这可能会重新测试,从而导致重复的fixture setup/teardown)
 

cache

pytest -h 查看命令行参数,关于 cache 参数的使用方式

> pytest -h

--lf, --last-failed   rerun only the tests that failed at the last 
                      run (or all if none failed)
--ff, --failed-first  run all tests, but run the last failures first.
                      This may re-order tests and thus lead to repeated fixture                                   											setup/teardown.
--nf, --new-first     run tests from new files first, then the rest of the tests sorted by 												file mtime
--cache-show=[CACHESHOW]
                      show cache contents, don't perform collection or tests. Optional      											argument: glob(default: '*').
--cache-clear         remove all cache contents at start of test run.

参数说明:

  • –lf 也可以使用 --last-failed 仅运行上一次失败的用例
  • –ff 也可以使用 --failed-first 运行全部的用例,但是上一次失败的用例先运行
  • –nf 也可以使用 --new-first 根据文件插件的时间,新的测试用例会先运行
  • –cache-show=[CACHESHOW] 显示.pytest_cache文件内容,不会收集用例也不会测试用例,选项参数: glob (默认: ‘*’)
  • –cache-clear 测试之前先清空.pytest_cache文件
     

–cache-show

案例

def test_01():
    a = "hello"
    b = "hello"
    assert a == b


def test_02():
    a = "hello"
    b = "hello world"
    assert a == b


def test_03():
    a = "hello"
    b = "hello world"
    assert a in b


def test_04():
    a = "hello"
    b = "hello world"
    assert a not in b

命令行输入 运行完成后,会有2个用例失败,2个用例成功

collecting ... 
 case/test_1.py ✓                                                                                                                                                                                         25% ██▌       

 case/test_1.py ⨯✓                                                                                                                                                                                        75% ███████▌  

 case/test_1.py ⨯                                                                                                                                                                                        100% ██████████

运行完成后,会在当前的目录生成一个 .pytest_cache 的缓存文件夹,层级结构如下

pytest运行_python压测

lastfailed 文件记录上一次运行失败的用例

{
  "test_x.py::test_02": true,
  "test_x.py::test_04": true
}

nodeids 文件记录所有用例的节点

[
  "test_x.py::test_01",
  "test_x.py::test_02",
  "test_x.py::test_03",
  "test_x.py::test_04"
]

于是可以通过 pytest –cache-show 命令查看cache目录

(pytest_env) ➜  apiAutomatic pytest --cache-show
Test session starts (platform: darwin, Python 3.7.6, pytest 6.2.1, pytest-sugar 0.9.4)
rootdir: /Users/jkc/PycharmProjects/apiAutomatic, configfile: pytest.ini
plugins: assume-2.4.2, sugar-0.9.4, rerunfailures-9.1.1, base-url-1.4.2, html-3.1.1, metadata-1.11.0, ordering-0.6, cov-2.10.1, repeat-0.9.1, xdist-2.2.0, forked-1.3.0, allure-pytest-2.8.29
cachedir: /Users/jkc/PycharmProjects/apiAutomatic/.pytest_cache
------------------------------------------------------------------------------------------------- cache values for '*' -------------------------------------------------------------------------------------------------
cache/lastfailed contains:
  {'case/test_1.py::test_02': True, 'case/test_1.py::test_04': True}
cache/nodeids contains:
  ['case/test_1.py::test_01',
   'case/test_1.py::test_02',
   'case/test_1.py::test_03',
   'case/test_1.py::test_04']
cache/stepwise contains:
  []
Results (0.02s):

 

–cache-clear

–cache-clear 用于在测试用例开始之前清空cache的内容

查看pytest关于cache的更多文档https://docs.pytest.org/en/latest/cache.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/165277.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • a标签下划线

    a标签下划线页面中有一处box中的a标签都被加上了下划线,查找元素却没有找到css中的underline。原因是<a>标签默认是有下划线的,而一般看到的<a>标签链接中的下划线都被覆盖掉了,所以误以为<a>标签的默认状态是没有下划线的,出现下划线是有css另外渲染的。其实下划线才是<a>标签的默认状态在head中加上下面一段覆盖掉<…

    2022年5月2日
    155
  • vue如何引入js文件_vue中引入外部js好麻烦

    vue如何引入js文件_vue中引入外部js好麻烦js文件一定要放在static下面,不可放在assets下面,因为assets下面的内容最终是要被打包的,而static下面的内容是不用打包直接放过去的;摘自:https://www.jb51.net/article/150517.htm遇到问题:今天做一个VUE的项目,在引入第三方依赖的JS文件时,遇到了一个问题:控制台的提示:UncaughtSyntaxError:Unexpectedtoken<按照提示进入文件,再看如下图:仔细看了看..

    2022年10月8日
    2
  • Latex 参考文献上标

    Latex 参考文献上标1.如何使连续的参考文献能够中间用破折号连起来?比如[6,7,8,9]变成[6-9]?方法:在文档开始前加上下面的语句命令\usepackage[numbers,sort&compress]{natbib}不但可以压缩参考文献标号,还可以进行排序,即无论正文里面的顺序怎样,显示出来都是先后顺序。在elsevier模板中,natbib包已经默认引用了,无需重新引用,改一下natb

    2025年10月16日
    2
  • uniqueidentifier类型_unique和normal

    uniqueidentifier类型_unique和normal@uuidasnvarchar(max))+””转载于:https://my.oschina.net/xuyuchends/blog/852105

    2025年10月2日
    1
  • sql中declare声明变量_sql怎么定义变量

    sql中declare声明变量_sql怎么定义变量一、变量的分类及特点1、变量的分类总体可以分为两大类:系统变量和用户自定义变量系统变量:包括全局变量和会话变量自定义变量:包括局部变量和用户用户变量2、变量的特点:1、系统变量的特点:(1)、每个客户机成功连接服务器后,都会产生与之对应的会话。会话期间,服务实例会在服务器内存中生成与该会话对应的会话系统变量。这些会话系统变量的初始值都是全局系统变量值的复制,有了标记不同的会话,会话系统又新增了一些变量,这些变量是全局扁郎没有…

    2022年8月20日
    15
  • Java switch 使用枚举类

    Java switch 使用枚举类开发过程中为了代码的可阅读性和可维护性,很多类型字段往往会习惯使用枚举去定义,可是在一些判断里面想用switch去代替ifelse就会出现以下问题publicenumSexType{MAN(1,”男”),GIRL(2,”女”),;privateinttype;privateStringwork;SexType(inttype,Stringwork){this.type=type;

    2022年7月14日
    16

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号