pytest
可自定义标记;@pytest.mark.自定义名称
# -*- coding:utf-8 -*-
# 作者:NoamaNelson
# 日期:2022/11/18
# 文件名称:test_mark.py
# 作用:自定义标记mark的使用
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import pytest
@pytest.mark.login
def test_login():
print("用户登陆")
@pytest.mark.case_a
def test_case_a():
print("执行用例a")
@pytest.mark.case_b
def test_case_b():
print("执行用例b")
@pytest.mark.quit
def test_quit():
print("用户退出")
pytest -s -m login test_mark.py
collected 4 items / 3 deselected / 1 selected
test_mark.py 用户登陆
.
pytest -s -m "login or case_a or case_b or quit" test_mark.py
collected 4 items
test_mark.py 用户登陆
.执行用例a
.执行用例b
.用户退出
.
pytest -s -m "not quit" test_mark.py
collected 4 items / 1 deselected / 3 selected
test_mark.py 用户登陆
.执行用例a
.执行用例b
.
============================================== warnings summary ==============================================
test_mark.py:11
F:\pytest_study\test_case\test_e\test_mark.py:11: PytestUnknownMarkWarning: Unknown pytest.mark.login - is th
is a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/s
table/mark.html
@pytest.mark.login
test_mark.py:15
F:\pytest_study\test_case\test_e\test_mark.py:15: PytestUnknownMarkWarning: Unknown pytest.mark.case_a - is t
his a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/
stable/mark.html
@pytest.mark.case_a
test_mark.py:19
F:\pytest_study\test_case\test_e\test_mark.py:19: PytestUnknownMarkWarning: Unknown pytest.mark.case_b - is t
his a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/
stable/mark.html
@pytest.mark.case_b
test_mark.py:23
F:\pytest_study\test_case\test_e\test_mark.py:23: PytestUnknownMarkWarning: Unknown pytest.mark.quit - is thi
s a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/st
able/mark.html
@pytest.mark.quit
-- Docs: https://docs.pytest.org/en/stable/warnings.html
================================ 3 passed, 1 deselected, 4 warnings in 0.03s =================================
pytest.ini
文件,加上自定义mark;pytest.ini
需要和运行的测试用例同一个目录,或在根目录下作用于全局;pytest.ini
,先看下本文如何避免警告,我们在用例同级目录创建一个pytest.ini
:
[pytest]
markers =
login: 这是用户登陆功能
case_a: 这是用例a
case_b: 这是用例b
quit: 这是用户退出功能
pytest -s -m "login or case_a or case_b or quit" test_mark.py
collected 4 items
test_mark.py 用户登陆
.执行用例a
.执行用例b
.用户退出
.
============================================= 4 passed in 0.03s ==============================================
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。