@pytest.mark.skip() #1、跳過方法或用例
@pytest.mark.skip(reason='跳過一個方法或一個測試用例') #2、跳過方法或用例,備注了原因
@pytest.mark.skipif(1==1,reason='跳過一個方法或一個測試用例') #3、加上判斷條件
場景一:某條用例已知存在bug,不執(zhí)行,直接跳過
import pytest
from page_obj.login_page import LoginPage
import allure
@allure.feature("登錄模塊")
@pytest.mark.smoke
class TestLogin:
@allure.title("成功登錄")
def test_login_success(self, app_page):
LoginPage(app_page).login('xxxxxxx', 'xxxxxx')
assert 1 == 1
@pytest.mark.skip(reason='已知bug不執(zhí)行')
@allure.title("成功登錄")
def test_login_error2(self, app_page):
assert 1 == 1

image.png

image.png
場景二:某個環(huán)境下不執(zhí)行某條用例,可加判斷
import pytest
from page_obj.login_page import LoginPage
import allure
@allure.feature("登錄模塊")
@pytest.mark.smoke
class TestLogin:
@allure.title("成功登錄")
def test_login_success(self, app_page):
LoginPage(app_page).login('xxxxxxx', 'xxxxxx')
assert 1 == 1
@pytest.mark.skipif(1==1,reason='正式環(huán)境不執(zhí)行此用例')
@allure.title("成功登錄")
def test_login_error2(self, app_page):
assert 1 == 1
場景三、賦值調(diào)用,簡化代碼
import pytest
from page_obj.login_page import LoginPage
import allure
myskip=pytest.mark.skipif(1==1,reason='正式環(huán)境不執(zhí)行此用例')
@allure.feature("登錄模塊")
@pytest.mark.smoke
class TestLogin:
@allure.title("成功登錄")
def test_login_success(self, app_page):
LoginPage(app_page).login('xxxxxxx', 'xxxxxx')
assert 1 == 1
@myskip
@allure.title("成功登錄")
def test_login_error2(self, app_page):
assert 1 == 1
@myskip
@allure.title("成功登錄2")
def test_login_error3(self, app_page):
assert 1 == 1