pytest运行_ios12自动清理缓存

pytest运行_ios12自动清理缓存前言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运行_ios12自动清理缓存

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

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


相关推荐

  • MySQL集群手册

    MySQL集群手册1 nbsp 集群与普通 MySQL 服务器区别 nbsp nbsp nbsp nbsp 与没有使用集群的 MySQL 相比 在 MySQL 集群内操作数据的方式没有太大的区别 执行这类操作时应记住两点 nbsp nbsp nbsp nbsp nbsp 1 表必须用 ENGINE NDB 或 ENGINE NDBCLUSTER 选项创建 或用 ALTER nbsp TABLE 选项更改 以使用 NDB 集群存储引擎在集群内复制它们 如果使用 mysqldump 的输出从已有数据库导入表 可在文本编

    2025年6月2日
    0
  • PLSQLDeveloper安装与配置

    PLSQLDeveloper安装与配置1,首先要有oracle数据库或者有oracle服务器,才可以实现使用PLSQLDeveloper工具连接到oracle数据库进行开发.2,下载PLSQLDeveloper并解压3,配置环境变量1)变量名:ORACLE_HOME变量值:E:\tool_01\PLSQLDeveloper\instantclient_11_22)变量名:TNS_ADMIN变量值:E:\tool_01…

    2022年6月7日
    37
  • statement 、prepareStatement的用法和解释「建议收藏」

    statement 、prepareStatement的用法和解释「建议收藏」转自:http://blog.csdn.net/QH_JAVA/article/details/48245945一、prepareStatement的用法和解释1.PreparedStatement是预编译的,对于批量处理可以大大提高效率.也叫JDBC存储过程…

    2022年6月10日
    93
  • 阿里java高级工程师面试100题「建议收藏」

    阿里java高级工程师面试100题「建议收藏」大型网站架构技术QQ群:3686148491,java堆,分新生代老年代,新生代有Eden,fromsurviver,tosurviver三个空间,堆被所有线程共。eden内存不足时,发生一次minorGC,会把fromsurvivor和eden的对象复制到tosurvivor,这次的to survivor就变成了下次的fromsurvivor,经过多次minorGC,默认15次…

    2022年6月9日
    55
  • BootstrapVue使用入门

    BootstrapVue使用入门网站:https://www.npmjs.com/package/bootstrap-vuehttps://bootstrap-vue.js.org/docs入门开始使用BootstrapVue,它基于世界上最流行的框架-Bootstrapv4,用于使用Vue.js构建响应迅速,移动优先的站点。Vue.jsv2.6是必需的,v2.6.10建议 引导v4.3是必需的,…

    2022年5月25日
    117
  • AdminLTE框架的基本使用

    AdminLTE框架的基本使用框架介绍:AdminLTE是一个完全响应管理模板。基于Bootstrap3,jQuery3.3.1这两个框架框架,易定制模板。适合多种屏幕分辨率,从小型移动设备到大型台式机。内置了多个页面,包括仪表盘、邮箱、日历、锁屏、登录及注册、404错误、500错误等页面。对于后台站点的模板渲染,有很大的作用。下载可以使用gitclone到本地gitclonehttp…

    2022年7月27日
    10

发表回复

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

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