• pytest 命令的使用


    1,查看命令

    pytest -h  ---> 查看命令

    2,执行文件里的case

                --->    pytest test_main_2.py
        正常执行测试case

    3,执行case时,显示详细case详细方法

    -v      --->    pytest -v test_main_2.py
        执行测试case,显示详细case详细方法

    4,加了-s不再显示Captured stdout call信息,但是会显示test session starts

    -s:   --->   加了-s不再显示Captured stdout call信息,但是会显示test session starts

    5,显示项目文件下所有模块里面case

    --collect-only ---> pytest --collect-only
        显示项目文件下所有模块里面case

    6,运行包含某个字符串的测试用例

    -k:    ---> pytest -v -k apple
         运行包含某个字符串的测试用例

    7,分组根据定义标签执行测试case

    -m:---> @pytest.mark.自定义标签
        分组根据定义标签执行测试case
    定义pytest.ini文件
    1. [pytest]
    2. markers:
    3. exit: test
    4. exit2: test2
    1. import pytest
    2. @pytest.mark.exit
    3. def test_001():
    4. assert 1==1
    5. @pytest.mark.exit
    6. def test_002():
    7. assert 1==1
    8. @pytest.mark.exit2
    9. def test_003():
    10. assert 1==1
    11. @pytest.mark.exit2
    12. def test_004():
    13. assert 1==1

    8,执行到错误的case时停止代码执行

    -x: --->  pytest -v -x .\test_main.py
        执行到错误的case时停止代码执行
     

     

    9,设置执行case允许失败最大次数,暂停执行case

    --maxfail=x ---> pytest --maxfail=2 -v .\test_main_2.py
       

     

    10,显示case执行的耗时时间

    --durations ---> pytest --durations=0 test_rq.py
    显示case执行的耗时时间
    1. import requests
    2. import pytest
    3. def test_1():
    4. re = requests.get('https://www.csdn.net')
    5. print(re)
    6. def test_2():
    7. re = requests.get('https://www.csdn.net')
    8. print(re)
    9. def test_3():
    10. re = requests.get('https://www.csdn.net')
    11. print(re)
    12. def test_4():
    13. re = requests.get('https://www.csdn.net')
    14. print(re)
    15. def test_5():
    16. re = requests.get('https://www.csdn.net')
    17. print(re)
    18. def test_6():
    19. re = requests.get('https://www.csdn.net')
    20. print(re)
        
       找出耗时最久的前五个case ---> pytest -s --durations=2 -v  test_rq.py

     

     

  • 相关阅读:
    java 使用documents4j将XML转为pdf文件的方式
    微信小程序中使用字体库_小程序使用自定义字体库
    字符驱动开发
    【python】内置函数汇总
    护眼台灯是智商税吗?书客、飞利浦、南卡三款台灯真实测评
    数据可视化?这些平台能处
    二维码智慧门牌管理系统:确保数据准确,强制校验GPS信号强度
    智能汽车行业软件供应链安全威胁与解决方案分享——小米IoT安全峰会
    FastDFS报错File name too long(fdfs报错File name too long)
    ret2shellcode
  • 原文地址:https://blog.csdn.net/qq_26086231/article/details/125434905