app自动化测试框架(五、跳过用例)
2021-08-05 本文已影响0人
HC2
@pytest.mark.skip() #1、跳过方法或用例
@pytest.mark.skip(reason='跳过一个方法或一个测试用例') #2、跳过方法或用例,备注了原因
@pytest.mark.skipif(1==1,reason='跳过一个方法或一个测试用例') #3、加上判断条件
场景一:某条用例已知存在bug,不执行,直接跳过
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不执行')
@allure.title("成功登录")
def test_login_error2(self, app_page):
assert 1 == 1
image.png
image.png
场景二:某个环境下不执行某条用例,可加判断
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='正式环境不执行此用例')
@allure.title("成功登录")
def test_login_error2(self, app_page):
assert 1 == 1
场景三、赋值调用,简化代码
import pytest
from page_obj.login_page import LoginPage
import allure
myskip=pytest.mark.skipif(1==1,reason='正式环境不执行此用例')
@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