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/165312.html原文链接:https://javaforall.net

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


相关推荐

  • emule最新服务器地址,关于emule 服务器列表

    emule最新服务器地址,关于emule 服务器列表关于emule服务器列表我给你几个服务器列表吧。打开选项—务器。然后点右边的“列表”。把以下网址复制进去,保存。然后把启动时自动更新服务器列表连接到服务器时更新服务器列表安全连接打上勾。所谓静态服务器,就是你把服务器优先值设定为高,然后下次登录时系统会自动先尝试你选定的服务器。Kad网络(KadNetwork)是一个完全分散的文件共享网络,它不被中心服务器使用。它执行KademliaP2P…

    2022年6月14日
    102
  • mysql数据库中查询数据的语句怎么写_mysql数据库多表查询

    mysql数据库中查询数据的语句怎么写_mysql数据库多表查询单表查询1、普通查询(1)命令:select*from<表名>;//通匹(2)命令:select<要查询的字段>from<表名>;2、去重查询(distinct)命令:selectdistinct<要查询的字段>from<表名>3、排序查询(orderby)升序:asc降序:desc降序排列命令:select<要查询的字段名>from<表名>orderby<要查询的字

    2022年9月3日
    5
  • java https pfx证书_httpclient https通过加载pfx证书获取数据

    java https pfx证书_httpclient https通过加载pfx证书获取数据httpclienthttps通过加载pfx证书获取数据(2015-05-0716:45:16)androidhttps通过加载pfx证书获取数据:http://www.devba.com/index.php/archives/5685.htmlRuntimeconfigurationofSSL/TLShttpclientonAndroidwithclientauthent…

    2022年6月1日
    57
  • 自定义web接收推送_Java Web

    自定义web接收推送_Java Webhttps://www.webjars.org/提供了很多js的jar,但是有时候有些js没有,我们也想打成jar,那怎么办?我们以jquery3.4.1版本为例子开始1.创建如下结构pom文件内容如下:<?xmlversion=”1.0″encoding=”UTF-8″?><projectxmlns=”http://maven.apache….

    2022年10月28日
    0
  • FPGA之SDRAM控制器设计(一)

    MT48LC128M4A2–32Megx4x4banks是512MSRAM,总体概述如下图分别从上电初始化,刷新,写,读四个部分进行设计,此外还包含主控状态机,一个顶层。1:上电初始化整体架构:从控制器到要控制的芯片可以分成20位的bus总线,时钟线sdr_clk,数据总线DQ以及DQM。上电时候主要是对bus总线的高4位也就是sdr_cmd进行配置。也就是要做的第一步,比较简单就是对sdr_cmd进行几次操作。其中注意在逻辑设计时候输出的sdr_clk时钟要和..

    2022年4月13日
    47
  • 关于PreferenceActivity的使用和一些问题的解决(自己定义Title和取值)

    关于PreferenceActivity的使用和一些问题的解决(自己定义Title和取值)

    2021年11月28日
    41

发表回复

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

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