pytest

对用例打标记,运行的时候,只运行打标记的用例。如冒烟测试

打标记步骤

1.先注册标记名

    在配置文件:pytest.ini 注册标记名,注意必须是这个文件名

  标签名加冒号后面可以写说明,必须是英文

   

2.给测试用例或测试类打标记

使用方法1:

  @pytest.mark.已注册的标记名

  

使用方法2:

  在模块文件里使用 pytestmark = pytest.mark.已注册标记名

 在测试类里使用pytestmark = pytest.mark.已注册标记名

3.运行时设置需要运行的标记名

  main文件 pytest命令行:-m, 标记名

pytest.main(["-s","-v",
"-m","smoke", # -m是打标记命令,smoke是标记名
"--alluredir=allure_dir"])

需要运行多个不同标记的用例时,如下

pytest.main(["-s","-v",
"-m","smoke or demo",
"--alluredir=allure_dir"])

pytest.main(["-s","-v",
"-m","smoke and demo",
"--alluredir=allure_dir"])

 指定标记名不被运行时:

pytest.main(["-s","-v",
"-m","not smoke",
"--alluredir=allure_dir"])
原文地址:https://www.cnblogs.com/sue2015/p/14760797.html