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

pytest常用参数

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

pytest常用参数

-k 运行匹配给定子字符串表达式的类、方法、function

E:bopytest 的目录
2022/02/18  10:31              .
2022/02/18  10:31              ..
2022/02/18  10:31              .pytest_cache
2022/02/17  18:54              ch1

>pytest -k "ch" 可运行ch1目录下的用例
>pytest -k "ch3" 无法获取ch1目录下的用例

--collect-only  只收集不运行
>pytest --collect-only

--tb=no  简洁打印输出结果   ---- 好像也不怎么简洁
>pytest --tb=no
其他输入类型 print mode (auto/long/short/line/native/no)

-m  只运行匹配给定标记表达式的测试
需要 import pytest,pytest.mark.关键字
pytest -m run_these --tb=no
只会运行 test_passing2、 test_passing3

import pytest

def test_passing():
    assert (1, 2, 3) == (1, 2, 3)

@pytest.mark.run_these
def test_passing2():
    assert (1, 2, 3) == (1, 2, 3)

@pytest.mark.run_these
def test_passing3():
    assert (1, 2, 3) == (1, 2, 3)

def test_passing4():
    assert (1, 2, 3) == (1, 2, 3)

注:运行会产生警告,在文件目录下新增一个pytest.ini文件,添加以下内容可取消警告
[pytest]
markers = run_these

-x  遇到fail即退出

--maxfail=num 在第num 个失败或错误后退出。

-s or --capture=no  打印错误输出print()语句

--lf  (last fail)  只打印错误用例
不带--lf
test_one.py .F..                                                                                
test_two.py F
pytest --lf
test_one.py F                                                                                              
test_two.py F

--ff  错误用例在前面
test_one.py F                                                                                      
test_two.py F                                                                                  
test_one.py ...

>pytest -v
>pytest --verbose
打印详细信息

-q  or --quite  不打印文件名
>pytest --quiet
.F..F

pytest -l  or –showlocals  运行失败打印变量的值   -- 所以这是lmn的l

>pytest --durations=3  跟运行时长有关系,运行最慢的3个?

>pytest --version   显示版本
pytest 6.2.4

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

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

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