栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pytest 命令的使用

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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文件
[pytest]
markers:
    exit: test
    exit2: test2
import pytest

@pytest.mark.exit
def test_001():
   assert 1==1


@pytest.mark.exit
def test_002():
   assert 1==1


@pytest.mark.exit2
def test_003():
   assert 1==1


@pytest.mark.exit2
def test_004():
   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执行的耗时时间
import requests
import pytest

def test_1():
    re = requests.get('https://www.csdn.net')
    print(re)

def test_2():
    re = requests.get('https://www.csdn.net')
    print(re)

def test_3():
    re = requests.get('https://www.csdn.net')
    print(re)

def test_4():
    re = requests.get('https://www.csdn.net')
    print(re)

def test_5():
    re = requests.get('https://www.csdn.net')
    print(re)

def test_6():
    re = requests.get('https://www.csdn.net')
    print(re)
        找出耗时最久的前五个case ---> pytest -s --durations=2 -v  test_rq.py

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/990914.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号