前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >pytest文档27-运行上次失败用例(--lf 和 --ff)

pytest文档27-运行上次失败用例(--lf 和 --ff)

作者头像
上海-悠悠
发布2018-10-24 11:25:12
1.7K0
发布2018-10-24 11:25:12
举报

前言

“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 =================
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-10-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 从零开始学自动化测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • pytest -h
  • —lf 和 —ff
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档