pytest运行_python压测

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


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)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • PLsql 永久注册码「建议收藏」

    PLsql 永久注册码「建议收藏」 注册码:ProductCode:4t46t6vydkvsxekkvf3fjnpzy5wbuhphqzserialNumber:601769password:xs374ca  原文链接:https://blog.csdn.net/sinat_33142609/article/details/72540025

    2022年7月24日
  • Anaconda与Pycharm的辨析[通俗易懂]

    Anaconda与Pycharm的辨析[通俗易懂]Anaconda与Pycharm的辨析Anaconda是python文件的一个包管理器,可以用它下载python文件的相关库和包,制作成python编程所需要的环境(模块、包、库)Pycharm是python文件的集成开发环境,在Pycharm上可以进行python文件的开发与调试,像VisualStudio之于C++,Eclipse之于Java。Pycharm里面也有下载python文件的相关库和包的功能,但很多库和包Pycharm可能因为网络及版本问题不能下载安装故Pycharm和Anacon

    2022年8月25日
  • GoLand 2022.01.4激活码(JetBrains全家桶)

    (GoLand 2022.01.4激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.htmlGTRPTN90LV-eyJsaWNlbnNlSW…

    2022年3月31日
  • Arduino学习笔记(12) — MPU6050与卡尔曼滤波算法实践「建议收藏」

    Arduino学习笔记(12) — MPU6050与卡尔曼滤波算法实践「建议收藏」01简介:WhyMPU6050?MPU6050等IMU传感器用于自平衡机器人,无人机,智能手机等。IMU传感器帮助我们在三维空间中获得连接到传感器的物体的位置。这些值通常是角度,以帮助我们确定其位置。它们用于检测智能手机的方向,或者用于Fitbit等可穿戴设备,它使用IMU传感器跟踪运动。MPU6050它是全球首例整合性6轴运动处理组件,俗称的六轴陀螺仪(xyz三轴的倾斜…

    2022年6月21日
  • 简单线性回归-最小二乘法推导过程

    简单线性回归-最小二乘法推导过程最近学习线性回归,自己推导了一下最小二乘法。 其他参考文章:https://blog.csdn.net/chasdmeng/article/details/38869941?utm_source=blogxgwz0https://blog.csdn.net/iterate7/article/details/78992015要是你在西安,感兴趣一起学习AIOPS,欢迎加入QQ群…

    2022年5月13日
  • goland2021永久激活码破解方法

    goland2021永久激活码破解方法,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月15日

发表回复

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

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