一、前言
pytest可以支持自定义标记,自定义标记可以把一个web项目划分为多个模块,然后指定模块名称执行。app自动化的时候,如果想android和ios公用一套代码时,也可以使用标记功能,标明哪些是ios用例,哪些是android用例,运行代码时指定mark名称运行。
二、mark标记
1、以下用例,标记test_send_http()为webtest
import pytest
@pytest.mark.webtest
def test_send_http():
print("890")# perform some webtest test for your app
def test_something_quick():
print("123")
def test_another():
print("456")
class TestClass:
def test_method(self):
print("678")
if __name__ == '__main__':
pytest.main(['-s', "-m=webtest",'test_class016.py'])
注意:只运行用webtest标记的测试,cmd运行的时候加-m参数,指定参数值为webtest,只能在终端情况可以使用