zoukankan      html  css  js  c++  java
  • pytest命令行参数

    1.-v:可以输出用例更加详细的执行信息,如下图

    C:Userscalecheckapi	est_cc>pytest test_m1.py -v
    =========================================================================================================== test session starts ============================================================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0 -- c:usersipharmacarepython37python.exe
    cachedir: .pytest_cache
    metadata: {'Python': '3.7.3', 'Platform': 'Windows-10-10.0.17134-SP0', 'Packages': {'pytest': '5.2.1', 'py': '1.8.0', 'pluggy': '0.13.0'}, 'Plugins': {'allure-pytest': '2.8.13', 'html': '2.0.0', 'metadata': '1.8.0', 'rerunfailures': '7.0'}}
    rootdir: C:Userscalecheckapi	est_cc
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 2 items
    
    test_m1.py::TestClass::test_one PASSED                                                                                                                                                                                                [ 50%]
    test_m1.py::TestClass::test_two PASSED                                                                                                                                                                                                [100%]
    
    ============================================================================================================ 2 passed in 0.14s =============================================================================================================
    
    C:Userscalecheckapi	est_cc>

    2.-s:输出用例中的调试信息,比如print等打印信息

    C:Userscalecheckapi	est_cc>pytest test_m1.py -s
    =========================================================================================================== test session starts ============================================================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
    rootdir: C:Userscalecheckapi	est_cc
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 2 items
    
    test_m1.py test_one方法执行
    .test_two方法执行
    .
    
    ============================================================================================================ 2 passed in 0.16s =============================================================================================================

    3.-m:根据标记执行特定的测试用例

    C:Userscalecheckapi	est_cc>pytest test_m1.py -m smoke -s
    =========================================================================================================== test session starts ============================================================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
    rootdir: C:Userscalecheckapi	est_cc
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 2 items / 1 deselected / 1 selected
    
    test_m1.py test_one方法执行
    .

    4.-k:执行用例中包含“关键字”的用例

    C:Userscalecheckapi	est_cc>pytest test_m1.py -k test_one -s        #test_one是用例名称,还可以是标签名或其它
    =========================================================================================================== test session starts ============================================================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
    rootdir: C:Userscalecheckapi	est_cc
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 2 items / 1 deselected / 1 selected
    
    test_m1.py test_one方法执行
    .
    
    ===================================================================================================== 1 passed, 1 deselected in 0.10s ======================================================================================================

    5.-q:简化控制台的输出

    C:Userscalecheckapi	est_cc>pytest test_m1.py -q
    ..                                                                                                                                                                                                                                    [100%]
    2 passed in 0.08s

     6. --collect-only:列出当前目录下所有的测试模块,测试类及测试函数

    C:Userscalecheckapi>pytest test_cc --collect-only
    ========================================================================= test session starts =========================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
    rootdir: C:Userscalecheckapi
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 4 items
    <Package C:Userscalecheckapi	est_cc>
      <Module test_m1.py>
        <Class TestClass>
            <Function test_one>
            <Function test_two>
      <Module test_m2.py>
        <Function test_three>
        <Function test_four>
    
    ======================================================================== no tests ran in 0.24s ========================================================================

    7.--tb=style(style可以是:no,line,short) 屏蔽测试用例执行输出的回溯信息,可以简化用例失败时的输出信息

    C:Userscalecheckapi	est_cc>pytest test_m1.py --tb=line
    ========================================================================= test session starts =========================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
    rootdir: C:Userscalecheckapi	est_cc
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 2 items
    
    test_m1.py F.                                                                                                                                                    [100%]
    
    ============================================================================== FAILURES ===============================================================================
    C:Userscalecheckapi	est_cc	est_m1.py:80: assert 1 == 2
    ===================================================================== 1 failed, 1 passed in 0.38s =====================================================================
    
    C:Userscalecheckapi	est_cc>pytest test_m1.py --tb=no
    ========================================================================= test session starts =========================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
    rootdir: C:Userscalecheckapi	est_cc
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 2 items
    
    test_m1.py F.                                                                                                                                                    [100%]
    
    ===================================================================== 1 failed, 1 passed in 0.34s =====================================================================
    
    C:Userscalecheckapi	est_cc>pytest test_m1.py --tb=short
    ========================================================================= test session starts =========================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
    rootdir: C:Userscalecheckapi	est_cc
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 2 items
    
    test_m1.py F.                                                                                                                                                    [100%]
    
    ============================================================================== FAILURES ===============================================================================
    _________________________________________________________________________ TestClass.test_one __________________________________________________________________________
    test_m1.py:80: in test_one
        assert  1==2
    E   assert 1 == 2
    ------------------------------------------------------------------------ Captured stdout call -------------------------------------------------------------------------
    test_one方法执行
    ===================================================================== 1 failed, 1 passed in 0.33s =====================================================================

     8.运行指定的测试类:pytest test_cc/m1_test.py::TestClass -v

    C:Userscalecheckapi>pytest test_cc/m1_test.py::TestClass -v
    =========================================================================================================== test session starts ============================================================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0 -- c:usersipharmacarepython37python.exe
    cachedir: .pytest_cache
    metadata: {'Python': '3.7.3', 'Platform': 'Windows-10-10.0.17134-SP0', 'Packages': {'pytest': '5.2.1', 'py': '1.8.0', 'pluggy': '0.13.0'}, 'Plugins': {'allure-pytest': '2.8.13', 'html': '2.0.0', 'metadata': '1.8.0', 'rerunfailures': '7.0'}}
    rootdir: C:Userscalecheckapi
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 2 items
    
    test_cc/m1_test.py::TestClass::test1 FAILED                                                                                                                                                                                           [ 50%]
    test_cc/m1_test.py::TestClass::test2 PASSED

    9.运行指定的测试方法:pytest test_cc/test_m2.py::test_three -v

    C:Userscalecheckapi>pytest test_cc/test_m2.py::test_three -v
    =========================================================================================================== test session starts ============================================================================================================
    platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0 -- c:usersipharmacarepython37python.exe
    cachedir: .pytest_cache
    metadata: {'Python': '3.7.3', 'Platform': 'Windows-10-10.0.17134-SP0', 'Packages': {'pytest': '5.2.1', 'py': '1.8.0', 'pluggy': '0.13.0'}, 'Plugins': {'allure-pytest': '2.8.13', 'html': '2.0.0', 'metadata': '1.8.0', 'rerunfailures': '7.0'}}
    rootdir: C:Userscalecheckapi
    plugins: allure-pytest-2.8.13, html-2.0.0, metadata-1.8.0, rerunfailures-7.0
    collected 1 item
    
    test_cc/test_m2.py::test_three PASSED                                                                                                                                                                                                 [100%]
  • 相关阅读:
    可能会搞砸你的面试:你知道一个TCP连接上能发起多少个HTTP请求吗?
    iOS笔记055
    iOS笔记053- Quartz2D-练习
    iOS笔记052- Quartz2D-绘图
    IOS笔记051-手势使用
    IOS笔记050-事件处理
    IOS笔记049-UITabBarController
    IOS笔记048-数据存储
    IOS笔记047-代理传值和block传值
    IOS笔记046-UIApplication/导航控制器
  • 原文地址:https://www.cnblogs.com/pipile/p/12696425.html
Copyright © 2011-2022 走看看