此文完全原创,不得随意转发。
今天在写代码的过程中遇到了这样一个warning:PytestUnknownMarkWarning: Unknown pytest.mark.test - is this a typo?
虽然不影响代码的执行,但是如果打标签的话想要单独执行某一条代码就没法进行筛选。
处理办法:
参考文档:https://docs.pytest.org/en/latest/mark.html
单个标签的话:
在contest里面添加代码:
def pytest_configure(config):
config.addinivalue_line(
"markers", "test" # test 是标签名
)
此方法只可以解决单个标签,如果有多个标签呢?把上面的代码进行修改:
def pytest_configure(config):
marker_list = ["test1","test2","test3"] # 标签名集合
for markers in marker_list:
config.addinivalue_line(
"markers", markers
)
还有一种方法:添加pytest.int 配置文件
[pytest]
markers = test1
test2
test3
总结:遇到这种问题,以上两种方法,二选一即可。