目录
前言
skip跳过测试方法
skip跳过测试类型
skif满足条件跳过
类和方法混合使用skipif
skip多处调用
方法内跳过
# -*- coding: utf-8 -*-
# @Time : 2021/10/24
# @Author : 大海
# @File : test_30.py
import pytest
# 直接跳过方法,reason 标记跳过原因,可省略 执行时加r选项,展示跳过原因
@pytest.mark.skip(reason='这是标记跳过用例的原因')
def test_login():
print('这是登录用例')
def test_logout():
print('这是登出用例')
class TestHomepage(object):
def test_one(self):
print('这是case1')
assert 1 == 1
@pytest.mark.skip()
def test_two(self):
print('这是case2')
assert 2 == 2
if __name__ == '__main__':
pytest.main(['-rs', 'test_30.py'])
# -*- coding: utf-8 -*-
# @Time : 2021/10/24
# @Author : 大海
import pytest
# 直接跳过测试类,reason 标记跳过原因,可省
@pytest.mark.skip()
class TestHomepage(object):
def test_one(self):
print('这是case1')
assert 1 == 1
def test_two(self):
print('这是case2')
assert 2 == 2
class TestMyPage(object):
def test_three(self):
print('这是case3')
assert 1 == 1
def test_four(self):
print('这是case4')
assert 2 == 2
if __name__ == '__main__':
pytest.main(['-rs', 'test_31.py'])
# -*- coding: utf-8 -*-
# @Time : 2021/10/24
# @Author : 大海
# @File : test_32.py
import pytest
app_version = 7.0
"""
1. @pytest.mark.skipif(1==1,reason='跳过一个方法或一个测试用例')
2. 被标记的类或方法,条件为布尔值,当条件为ture时,会被跳过,否则不跳过
3. reason 标记跳过原因,可省
"""
@pytest.mark.skipif(app_version <= 8.0, reason='APP版本小于等于8.0时不执行')
class TestHomepage(object):
def test_one(self):
print('这是case1')
assert 1 == 1
def test_two(self):
print('这是case2')
assert 2 == 2
@pytest.mark.skipif(app_version > 8.0, reason='APP版本大于等于8.0时不执行')
class TestMyPage(object):
def test_three(self):
print('这是case3')
assert 1 == 1
def test_four(self):
print('这是case4')
assert 2 == 2
if __name__ == '__main__':
pytest.main(['-rs', 'test_32.py'])
多个skipif时,满足1个条件即跳过
# -*- coding: utf-8 -*-
# @Time : 2021/10/24
# @Author : 大海
# @File : test_33.py
import pytest
app_version = 9.0
@pytest.mark.skipif(app_version <= 8.0, reason='APP版本小于等于8.0时不执行')
class TestHomepage(object):
def test_one(self):
print('这是case1')
assert 1 == 1
@pytest.mark.skipif(app_version <= 9.0, reason='此用例APP版本小于等于9.0时不执行')
def test_two(self):
print('这是case2')
assert 2 == 2
if __name__ == '__main__':
pytest.main(['-rs', 'test_33.py'])
# -*- coding: utf-8 -*-
# @Time : 2021/10/24
# @Author : 大海
# @File : test_34.py
import pytest
app_version = 9.0
app_version_nine = pytest.mark.skipif(app_version <= 9.0, reason='此用例APP版本小于等于9.0时不执行')
@pytest.mark.skipif(app_version <= 8.0, reason='APP版本小于等于8.0时不执行')
class TestHomepage(object):
def test_one(self):
print('这是case1')
assert 1 == 1
@app_version_nine
def test_two(self):
print('这是case2')
assert 2 == 2
if __name__ == '__main__':
pytest.main(['-rs', 'test_34.py'])
# -*- coding: utf-8 -*-
# @Time : 2021/10/24
# @Author : 大海
# @File : test_35.py
import pytest
app_version = 9.0
@pytest.mark.skipif(app_version <= 8.0, reason='APP版本小于等于8.0时不执行')
class TestHomepage(object):
def test_one(self):
print('这是case1')
pytest.skip('跳过此case')
assert 1 == 1
def test_two(self):
print('这是case2')
assert 2 == 2
if __name__ == '__main__':
pytest.main(['-rs', 'test_35.py'])