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%]
  • 相关阅读:
    科普文,无论在哪选配计算机,都要懂得常识 (任务5)
    任务5 配机网站关注热点解读
    科普文,解析品牌机的配置特点,选配计算机可以这么做(任务4)
    任务4 解析品牌机配置
    立足于应用需求,看到整体性能,评价计算机的性能(任务3)
    科普文,分享计算机优化的套路,停掉不需要的进程(任务3)
    任务3对电脑进行评价,硬件健康,性能测试, WINDOWS体验指数
    任务2认知计算机系统(计算机系统是一个生态系统,分为硬件系统和软件系统,互为支撑)
    数据库程序接口——JDBC——API解读第一篇——建立连接的核心对象
    数据库程序接口——JDBC——API解读第二篇——执行SQL的核心对象
  • 原文地址:https://www.cnblogs.com/pipile/p/12696425.html
Copyright © 2011-2022 走看看