pytest-skip跳过用例

skip

使用跳过装饰器来进行标记:@pytest.mark.skip(self,reason=None)

  • 无条件跳过
# -*- coding: utf-8 -*-
'''
@Time : 2021/1/25
@Author : 
@File : skip.py
@describe : 
'''

import pytest

class TestCase:

    @pytest.mark.skip('不执行')
    def test_one(self):
        print('测试用例一')

    def test_two(self):
        print('测试用例二')

if __name__ == '__main__':
    pytest.main(['-s','skip.py'])

运行结果:
pytest-skip跳过用例_第1张图片

skipif

  • 符合条件时才跳过
# -*- coding: utf-8 -*-
'''
@Time : 2021/1/25
@Author : 
@File : skip.py
@describe : 
'''

import pytest

condition = '跳过'
class TestCase:

    @pytest.mark.skipif(condition=='执行',reason='test')
    def test_one(self):
        print('测试用例一')

    def test_two(self):
        print('测试用例二')

    @pytest.mark.skipif(condition=='跳过',reason='test')
    def test_three(self):
        print('测试用例三')

if __name__ == '__main__':
    pytest.main(['-s','skip.py'])

运行结果:
pytest-skip跳过用例_第2张图片

你可能感兴趣的:(pytest学习笔记,python)