• 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

     

     

  • 相关阅读:
    详解JMM
    2022淘宝双十一优惠券如何叠加使用?淘宝双十一优惠券叠加规则介绍
    【生成式AI】ChatGPT 原理解析(2/3)- 预训练 Pre-train
    c++ - 第11节 - stack和queue类
    老牌期货公司综合实力强开户体验佳
    大数据Apache Druid(八):Druid JDBC API和其他OLAP分析框架对比
    hashMap不同版本的区别
    mock的基本用法
    Triangle Attack: A Query-efficient Decision-based Adversarial Attack
    企业软件定制开发的重点是什么?|app小程序网站建设
  • 原文地址:https://blog.csdn.net/qq_26086231/article/details/125434905