当前位置:网站首页>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的用例,标签表达式有双引号,单引号不能识别
边栏推荐
猜你喜欢
The intern left a big hole when he ran away and made two online problems, which made me miserable
AWD学习
Redis——大Key問題
Data science [9]: SVD (2)
WLAN相关知识点总结
Redis - big key problem
Amazon AWS data Lake Work Pit 1
一起学习SQL中各种join以及它们的区别
Don't use the new WP collection. Don't use WordPress collection without update
链表(线性结构)
随机推荐
Kotlin - 验证时间格式是否是 yyyy-MM-dd HH:mm:ss
CUDA中的异步数据拷贝
Codeforces Round #797 (Div. 3) A—E
Decryption skills of encrypted compressed files
分布式事务 :可靠消息最终一致性方案
The intern left a big hole when he ran away and made two online problems, which made me miserable
VLAN experiment of switching technology
Linear DP (split)
一起学习SQL中各种join以及它们的区别
Redis - grande question clé
Codeforces Round #797 (Div. 3) A—E
计算属性普通函数写法 和 set get 写法
Redis——热点key问题
Summary of WLAN related knowledge points
LeetCode 27. Removing Elements
LeetCode 40. Combined sum II
Linked list (linear structure)
重载全局和成员new/delete
Pbootcms collection and warehousing tutorial quick collection release
The difference between session and cookies