pytest使用自定义标记mark
2021-06-08 本文已影响0人
Chaweys
pytest使用自定义标记mark
#coding=utf-8
import pytest
@pytest.mark.weibo
def test_weibo():
print("测试微博")
@pytest.mark.toutiao
def test_toutiao():
print("测试头条")
def test_nothing():
print("没有标记")
@pytest.mark.testmark
class TestMark:
def test_mark(self):
print("测试类标记")
if __name__ == '__main__':
pytest.main(["-s","-m weibo","test_mark.py"])
"""
pytest.main(["-m", "run_first"])
使用-m 对用例进行标记,用例需注释@pytest.mark.xxx,将xxx作为参数传入
使用-m "mark1 and mark2"可以同时选中带有这两个标记的所有测试用例。
使用-m "mark1 and not mark2"选中带有与mark1的测试用例,而过滤掉带有mark2的测试用例
使用-m "mark1 or mark2"则选中带有mark1或者mark2的所有测试用例
结果:
collected 4 items / 3 deselected / 1 selected
test_mark.py 测试微博
.
============================== warnings summary ===============================
test_mark.py:4
E:\ProjectStudy\Pytest框架\test_mark.py:4: PytestUnknownMarkWarning: Unknown pytest.mark.weibo - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.weibo
test_mark.py:8
E:\ProjectStudy\Pytest框架\test_mark.py:8: PytestUnknownMarkWarning: Unknown pytest.mark.toutiao - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.toutiao
test_mark.py:15
E:\ProjectStudy\Pytest框架\test_mark.py:15: PytestUnknownMarkWarning: Unknown pytest.mark.testmark - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.testmark
-- Docs: https://docs.pytest.org/en/stable/warnings.html
================= 1 passed, 3 deselected, 3 warnings in 0.20s =================
"""