-k 运行匹配给定子字符串表达式的类、方法、function
E:\bopytest 的目录
2022/02/18  10:31    <dir>          .
2022/02/18  10:31    <dir>          ..
2022/02/18  10:31    <dir>          .pytest_cache
2022/02/17  18:54    <dir>          ch1</dir></dir></dir></dir>
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
skip跳过某些用例
运用场景:需要调用其他接口,而其他接口报错或无返回,则用例不运行;或连接数据库查数,查不到不运行
@pytest.mark.skip
@pytest.mark.skipif
pytest.skip(reason)
-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.4Original: https://blog.csdn.net/summeryan2011/article/details/122998114
Author: summeryan2011
Title: pytest常用参数
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/772463/
转载文章受原作者版权保护。转载请注明原作者出处!