当前位置:网站首页>pytest(2) mark功能
pytest(2) mark功能
2022-07-02 06:22:00 【bthtth】
1\ 标记测试用例
pytest.mark.标签名
可以用来标记单条测试函数,或者测试类
# 文件名 test_mark.py
import pytest
@pytest.mark.mark_class # 标记测试类,将标记类中的每一个测试函数
class Test_mark:
def test_case_1(self):
print("case_1,mark_class")
@pytest.mark.mark_func # 拥有两个标签 mark_class,mark_func
def test_case_2(self):
print("caes_2,mark_class,mark_func")2\ 根据标签执行测试用例 在命令行输入pytest -m 标签名
在命令行,切换到test_mark.py所在的文件夹,test_mark.py是上面的代码所在文件

输入pytest -m mark_calss 执行有class_class标签的用例

报错了 Unknown pytest.mark.mark_class - is this a typo?
需要注册
在test_mark.py的根目录baidu下,创建pytest.ini文件

在pytest.ini文件输入以下代码
addopts = --strict-markers 严格匹配标签名称
markers= ^^^^^ 就是自定义的标签
[pytest]
addopts = --strict-markers
markers =
mark_class: marks tests as mark_class (deselect with '-m "not slow"')
mark_func:marks tests as mark_class
然后就可以运行了,
mark_calss 运行了测试类中的两个标签
mark_func 只用写一个标签,收集两个用例,执行一个用例

还可以和逻辑运行符筛选用例
pytest -m mark_calss and not mark_func 运行 有mark_calss 但是没有mark_func的用例,标签表达式有双引号,单引号不能识别

边栏推荐
猜你喜欢
随机推荐
Tensorrt command line program
介绍两款代码自动生成器,帮助提升工作效率
深入了解JUC并发(一)什么是JUC
LeetCode 78. subset
LeetCode 47. Full arrangement II
Amazon AWS data Lake Work Pit 1
Sudo right raising
It is said that Kwai will pay for the Tiktok super fast version of the video? How can you miss this opportunity to collect wool?
Shardingsphere JDBC
Generic classes and parameterized classes of SystemVerilog
CUDA中的线程层次
Cglib代理-代码增强测试
Three suggestions for all students who have graduated and will graduate
一口气说出 6 种实现延时消息的方案
FE - Eggjs 结合 Typeorm 出现连接不了数据库
Use of Arduino wire Library
Idea announced a new default UI, which is too refreshing (including the application link)
IDEA公布全新默认UI,太清爽了(内含申请链接)
RestTemplate请求时设置请求头,请求参数,请求体。
LeetCode 83. Delete duplicate elements in the sorting linked list









