前言

“80%的bug集中在20%的模块,越是容易出现bug的模块,bug是越改越多“平常我们做手工测试的时候,比如用100个用例需要执行,其中10个用例失败了,

当开发修复完bug后,我们一般是重点测上次失败的用例。

那么自动化测试也一样,当用例特别多时,为了节省时间,第一次部分用例失败了,修复完之后,可以只测上次失败的用例。

pytest -h

命令行输入pytest -h,找到里面两个命令行参数: --lf 和 --ff

  • --lf, --last-failed 只重新运行上次运行失败的用例(或如果没有失败的话会全部跑)
  • --ff, --failed-first 运行所有测试,但首先运行上次运行失败的测试(这可能会重新测试,从而导致重复的fixture setup/teardown)

--lf 和 --ff

lf是last-failed的缩写,我第一次运行全部测试用例有4个通过passed, 2个失败failed,1个error

E:\YOYO\web_conf_py>pytest
============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: E:\YOYO\web_conf_py, inifile:
plugins: metadata-1.7.0, html-1.19.0
collected 7 items baidu\test_1_baidu.py .. [ 28%]
baidu\test_2.py FF [ 57%]
blog\test_2_blog.py ..E [100%] =================================== ERRORS ====================================
__________________________ ERROR at setup of test_05 __________________________
file E:\YOYO\web_conf_py\blog\test_2_blog.py, line 11
def test_05(start, open_baidu):
E fixture 'open_baidu' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, metadata, monkeypatch, open_blog, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, start, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them. E:\YOYO\web_conf_py\blog\test_2_blog.py:11
================================== FAILURES ===================================
___________________________________ test_06 ___________________________________ start = None, open_baidu = None def test_06(start, open_baidu):
print("测试用例test_01")
> assert 1==2
E assert 1 == 2 baidu\test_2.py:5: AssertionError
---------------------------- Captured stdout call -----------------------------
测试用例test_01
___________________________________ test_07 ___________________________________ start = None, open_baidu = None def test_07(start, open_baidu):
print("测试用例test_02")
> assert 1==2
E assert 1 == 2 baidu\test_2.py:9: AssertionError
---------------------------- Captured stdout call -----------------------------
测试用例test_02
================= 2 failed, 4 passed, 1 error in 0.21 seconds =================

如果只想运行其中2个failed的和1error用例,那么可以直接在cmd输入指令

pytest --lf

E:\YOYO\web_conf_py>pytest --lf
============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: E:\YOYO\web_conf_py, inifile:
plugins: metadata-1.7.0, html-1.19.0
collected 7 items / 4 deselected
run-last-failure: rerun previous 3 failures baidu\test_2.py FF [ 66%]
blog\test_2_blog.py E [100%] ========================== 2 failed, 4 deselected, 1 error in 0.16 seconds===========================

如果想先运行上次失败的,后运行其它通过的用例

pytest --ff

E:\YOYO\web_conf_py>pytest --ff
============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: E:\YOYO\web_conf_py, inifile:
plugins: metadata-1.7.0, html-1.19.0
collected 7 items
run-last-failure: rerun previous 3 failures first baidu\test_2.py FF [ 28%]
blog\test_2_blog.py E [ 42%]
baidu\test_1_baidu.py .. [ 71%]
blog\test_2_blog.py .. [100%] ================= 2 failed, 4 passed, 1 error in 0.14 seconds =================

---------------------------------pytest结合selenium自动化完整版-------------------------

全书购买地址 https://yuedu.baidu.com/ebook/902224ab27fff705cc1755270722192e4536582b

作者:上海-悠悠 QQ交流群:874033608

也可以关注下我的个人公众号:yoyoketang

pytest文档26-运行上次失败用例(--lf 和 --ff)的更多相关文章

  1. 运行上次失败用例(--lf 和 --ff)

    前言 “80%的bug集中在20%的模块,越是容易出现bug的模块,bug是越改越多“平常我们做手工测试的时候,比如用100个用例需要执行,其中10个用例失败了,当开发修复完bug后,我们一般是重点测 ...

  2. pytest文档3-pycharm运行pytest

    前言 上一篇pytest文档2-用例运行规则已经介绍了如何在cmd执行pytest用例,平常我们写代码在pycharm比较多 写完用例之后,需要调试看看,是不是能正常运行,如果每次跑去cmd执行,太麻 ...

  3. pytest文档41-参数化 ids 用例描述为中文时控制台输出unicode编码问题(pytest_collection_modifyitems)

    前言 使用 pytest.mark.parametrize 参数化的时候,加 ids 参数用例描述有中文时,在控制台输出会显示unicode编码,中文不能正常显示. 使用 pytest_collect ...

  4. pytest文档44-allure.dynamic动态生成用例标题

    前言 pytest 结合 allure 描述用例的时候我们一般使用 @allure.title 和 @allure.description 描述测试用例的标题和详情. 在用例里面也可以动态更新标题和详 ...

  5. pytest文档7-pytest-html生成html报告

    前言 pytest-HTML是一个插件,pytest用于生成测试结果的HTML报告.兼容Python 2.7,3.6 pytest-html 1.github上源码地址[https://github. ...

  6. Python接口测试实战4(下) - 框架完善:用例基类,用例标签,重新运行上次失败用例

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  7. pytest文档16-用例a失败,跳过测试用例b和c并标记失败xfail

    前言 当用例a失败的时候,如果用例b和用例c都是依赖于第一个用例的结果,那可以直接跳过用例b和c的测试,直接给他标记失败xfail 用到的场景,登录是第一个用例,登录之后的操作b是第二个用例,登录之后 ...

  8. pytest文档2-用例运行规则

    用例设计原则 文件名以test_*.py文件和*_test.py 以test_开头的函数 以Test开头的类 以test_开头的方法 所有的包pakege必须要有__init__.py文件 help帮 ...

  9. pytest文档51-内置fixture之cache使用

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

随机推荐

  1. Pg168-1

    1.Pg168-1 package org.hanqi.pn0120; public class Computer { private double neicundx=10; public doubl ...

  2. 转发:RocketMQ与kafka的对比

    淘宝内部的交易系统使用了淘宝自主研发的Notify消息中间件,使用Mysql作为消息存储媒介,可完全水平扩容,为了进一步降低成本,我们认为存储部分可以进一步优化,2011年初,Linkin开源了Kaf ...

  3. js和php计算图片自适应宽高算法实现

    js Code: <script> $width = $(imgobj).width(); //图原始宽 $newheight = $(imgobj).height(); //图原始高 $ ...

  4. Winsock—I/O模型之选择模型(一)

    Winsock中提供了一些I/O模型帮助应用程序以异步方式在一个或多个套接字上管理I/O. 这样的I/O模型有六种:阻塞(blocking)模型,选择(select)模型,WSAAsyncSelect ...

  5. Oracle登录

    一.安装Oracle 二.打开Database Configuration Assistant 三.打开SQL Plus 1.打开SQL Plus 2.输入用户名sys 3.输入口令1 as sysd ...

  6. LINUX 下挂载 exfat 格式 u 盘或移动硬盘

    apt-get update apt-get install exfat-utils

  7. Oracle11g 基础 --即将发布

    由于整理发布于博客园较为麻烦,所以这可能需要一点时间. 敬请期待.

  8. OpenJudge——0003:jubeeeeeat

    OpenJudge——0003:jubeeeeeat 描述 众所周知,LZF很喜欢打一个叫Jubeat的游戏.这是个音乐游戏,游戏界面是4×4的方阵,会根据音乐节奏要求玩家按下一些指定方块(以下称co ...

  9. JAVAEE——宜立方商城08:Zookeeper+SolrCloud集群搭建、搜索功能切换到集群版、Activemq消息队列搭建与使用

    1. 学习计划 1.solr集群搭建 2.使用solrj管理solr集群 3.把搜索功能切换到集群版 4.添加商品同步索引库. a) Activemq b) 发送消息 c) 接收消息 2. 什么是So ...

  10. 理解URI

    ---恢复内容开始--- 参考 https://zh.wikipedia.org/wiki/%E7%BB%9F%E4%B8%80%E8%B5%84%E6%BA%90%E6%A0%87%E5%BF%97 ...