前言

“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. Flask 对象关系

    建立一个关系 from sqlalchemy import Column, Integer, String, MetaData, ForeignKey from sqlalchemy.ext.decl ...

  2. java解析Xml格式的字符串

    最近在工作中,需要调别的接口,接口返回的是一个字符串,而且内容是xml格式的,结果在解析json的时候报错,最终修改了接口的返回方式,以Map返回, 才得以接收到这个xml的字符串,然后通过dom4j ...

  3. JSP的学习二(指令与标签)

    一:page指令 1.JSP的指令 放在<%@ 指令 属性=“值”%> 主要有page,include,tablib. 2.page指令 用于定义JSP页面的各种属性,作用于是JSP的整个 ...

  4. Ionic Js三:下拉刷新

    在加载新数据的时候,我们需要实现下拉刷新效果,代码如下: HTML 代码 <body ng-app="starter" ng-controller="actions ...

  5. 预备作业02:体会做中学(Learning By Doing)

    1.很惭愧,我并没有什么技能能强过大家. 2...... 3.我觉得培养一个技能,必须要通过勤勉的练习,认真的学习,还有不断地结合实践. 4.我觉得我学习<程序设计与数据结构>之后应该对程 ...

  6. [转载] 你所不知道的TIME_WAIT和CLOSE_WAIT

    前言 本文转载自 https://mp.weixin.qq.com/s/FrEfx_Yvv0fkLG97dMSTqw.很久前看到Vincent Bernat在博客中写了一遍关于TCP time-wai ...

  7. Java 异常处理之 论 finally块何时候不走

    一. exit退出异常: import java.util.Scanner; public class Test3exit { /** * @param 房山的猫 * finally什么时候不走 * ...

  8. [java] java中的初始化顺序

    先看程序: package init_cls; class A{ {System.out.println("i am in the class A!");} static { Sy ...

  9. requests爬取百度音乐

    使用requests爬取百度音乐,我想把当前热门歌手的音乐信息爬下来. 首先进行url分析,可以看到: 歌手网页: 薛之谦网页: 可以看到,似乎这些路劲的获取一切都很顺利,然后可以写代码: # -*- ...

  10. Centos7下shell脚本添加开机自启动

    添加开机自启脚本,注意都需要用绝对路径 psubscribe.sh脚本中的内容: nohup /usr/bin/php -f /data/aliyun51015cn/redisChannel/psub ...