pytest标记
pytest查找策略,默认情况下,pytest会递归查找当前目录下所以以test开始或结尾的python脚本,并执行文件内所有以test开始或结束的函数和方法
实例:
import pytest
class TestCase02(object):
def test01(self):
print(‘test01‘)
def add(self):
print(‘add‘)
def test02(self):
print(‘test02‘)
if __name__ == ‘__main__‘:
pytest.main([‘-vs‘,‘test02.py‘])
执行结果如下:
仅执行test01和test02,未执行add
标记测试函数
由于某种原因(如test_func2的功能尚未开发完成),我们只想执行指定的测试函数,在pytest中有几种解决方法:
1、显示指定函数名,通过::标记
test_no_mark.py::test_func1
2、使用模糊匹配,使用-k选项标识
pytest -k func1 test_no_mark.py
3、使用pytest.mark在函数上进行标记
给用例打标签
注册标签名,通过.ini配置文件,格式如下:
[pytest]
markers =
do:do
undo:undo
在用例上打标记
import pytest
@pytest.mark.do
def test1():
print(‘1‘)
# :: -k test mark
@pytest.mark.undo
def test2():
print(‘2‘)
配置文件:
原文:https://www.cnblogs.com/yronl/p/14463522.html