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

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


相关推荐

  • c语言系统主函数流程图,c语言流程图【调解方式】

    c语言系统主函数流程图,c语言流程图【调解方式】虽然电脑已经很普遍了,但是一些年长的人对电脑的操作不是很熟悉,比如在使用win7系统时一旦遇到c语言流程图时就懵了,对于c语言流程图处理起来相对来说较简单,按照我们的步骤处理c语言流程图很容易上手,c语言流程图具体处理方法如下:c语言的流程图怎么画?答:如果会编程序而不会画流程图,建议先把自己的程序研究一遍。若是画主程序流程图,那就需看懂主函数的程序,按照main()函数中的具体书写过程来画,例…

    2025年6月18日
    4
  • MyEclipse、eclipse代码自动补全(联想输入)「建议收藏」

    MyEclipse、eclipse代码自动补全(联想输入)「建议收藏」MyEclipse(eclipse)的自动补全(联想输入)分两种,直接提示和按快捷键提示,设置方法分别如下 一、每次输入都自动提示 Window->preferences->Java->Editor->ContentAssist 再右下角AutoactivationtriggersforJava里面改为 Java代码  abcdefghijkl

    2022年5月7日
    282
  • windows 2008文件服务器审计

    windows 2008文件服务器审计windows2008或者windows2008r2,系统做域内的文件服务器,能否做到谁删除某个共享出来的文件夹或者文件的操作审计?审计级别能做到怎么样一个程度?回答:依据您的问题您想知道Windows2008文件服务器的审计相关。依据我的经验,这个要分成两种情况:1.在远端访问,就是通过网络路径访问;2.在本地上本地访问共享文件,就是在创建的机器上访问;远端访问访问共享文件…

    2022年6月4日
    79
  • pycharm打开全部变成乱码_pycharm控制台输出中文乱码

    pycharm打开全部变成乱码_pycharm控制台输出中文乱码如上图所示:PyCharm默认打开时,pythonconsole中如果用到windows下cmd里的命令时,会输出乱码,原因:cmd默认的编码是gbk(代码页:936),而pythonconsole里面的编码是utf-8(代码页:65001),由于编码不一致,所以输出时会出现乱码解决办法:如下:1、File-Setting-Search-console-pythonconsol

    2022年8月27日
    5
  • Linux中搭建Nginx环境[通俗易懂]

    Linux中搭建Nginx环境[通俗易懂]CentOs7环境中一、安装pcre依赖 1.下载 本地上传或者联网下载pcre压缩文件依赖 2. 解压pcre压缩包 命令:tar -zxvf pcre-8.37.tar.gz 3. 在解压目录下执行 ./configure 在当前目录运行configure文件 …

    2022年6月13日
    30
  • git学习——设置gitlab、github默认push的用户名和密码

    在使用git的时候,不同的环境下,当你重新安装git,最好在开始的时候就配置一下默认的git的用户名和密码,这样子就可以在每次的push的时候不需要手动的在去输入git的用户名和密码,提高执行的效率。 环境:Windows环境已经安装git,我使用的gitlab(github和这样配一样),gitlab的用户名742981086@qq.com 下面在Windows环境中进行配置过程的演示, 1

    2022年2月25日
    323

发表回复

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

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