【pytest-03】pytest- 使用自定义标记mark
一、pytest 通过@pytest.mark进行自定义标记,自定义标记可以把一个 web 项目划分多个模块,然后指定模块名称执行
代码参考:
pytest_mark.py:
import pytest
@pytest.mark.test1
def test_weixin():
print("测试输出1")
@pytest.mark.test2
def test_toutou():
print("测试输出2")
@pytest.mark.test3
def test_toutuo1():
print("测试输出3")
@pytest.mark.test4
class TestClass:
def test_method(self):
print("测试输出4")
def testnoMark():
print("没有标记测试")
if __name__ == '__main__':
pytest.main(['-s', '-m test1', 'pytest_mark.py'])
返回结果:

二、不想标记test1的用例,我们直接取反即可
if __name__ == '__main__':
pytest.main(['-s', '-m not test1', 'pytest_mark.py'])

三、执行多个自定义标记的用例
if __name__ == '__main__':
pytest.main(['-s', '-m test1 or test3', 'pytest_mark.py'])

本文来自博客园,作者:橘子偏爱橙子,转载请注明原文链接:https://www.cnblogs.com/xfbk/p/16011075.html

浙公网安备 33010602011771号