pytest教程之skip執行時跳過用例

2021-10-13 01:47:52 字數 848 閱讀 9298

在實際的自動化測試過程中,我們會因為某些原因想跳過部分用例的執行,例如個別用例在某個環境中無法執行時。這時候使用pytest的skip功能可以跳過這些用例執行。下面看例子:

import pytest

import sys

skipmark = pytest.mark.skip(reason=

"不能在staging環境執行"

)class testsikp:

@pytest.mark.skip(reason=

"不執行,因為沒寫好"

) def test_one(self):

print(1)

@skipmark

def test_two(self):

print(2)

# condition為true才跳過

@pytest.mark.skipif(sys.platform!=

'win32',reason=

'不能在windows平台執行'

) def test_three(self):

print(sys.platform)

skipped                                 [ 33%]

skipped: 不執行,因為沒寫好

skipped [ 66%]

skipped: 不能在staging環境執行

skipped [100%]

skipped: 不能在windows平台執行

pytest跳過執行skip和skipif

相關函式 pytest.mark.skip pytest.mark.skipif 可以看看原函式 staticmethod def skipif condition,reason none skip the given test function if eval condition results ...

pytest八 skip 跳過用例

這是乙個快速指南,介紹如何在不同情況下跳過模組中的測試 1.無條件地跳過模組中的所有測試 pytestmark pytest.mark.skip all tests still wip 2.根據某些條件跳過模組中的所有測試 pytestmark pytest.mark.skipif sys.plat...

pytest教程之自定義mark

實際的自動化測試專案中,我們的用例通常會放在多個py檔案中,如果我們只想執行其中部分用例,該怎麼做呢?pytest提供的mark功能能夠幫助我們解決這個問題。下面看具體做法。pytest markers you this is you me this is metest a.py中 用例 impor...