pytest-skip跳過用例
阿新 • • 發佈:2021-01-27
技術標籤:pytest學習筆記python
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'])
執行結果:
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'])
執行結果: