pytest -k 參數(shù)的用法—筆記

-k參數(shù)的用法,示例代碼如下:

def test_a():
    print("test_a")

class TestDemo():

    def test_one(self):
        print("開始執(zhí)行 test_one 方法")
        x = 'this'
        assert 'h' in x

    def test_two(self):
        print("開始執(zhí)行 test_two 方法")
        x = 'hello'
        assert 'e' in x

    def test_three(self):
        print("開始執(zhí)行 test_three 方法")
        a = 'hello'
        b = 'hello world'
        assert a not in b

class TestDemo1():
    def test_one(self):
        print("開始執(zhí)行 test_one 方法")
        a = 'hello'
        b = 'hello world'
        assert a not in b

    def test_o2(self):
        print("開始執(zhí)行 test_o2 方法")
        x = 'this'
        assert 'h' in x

    def test_3(self):
        print("開始執(zhí)行 test_3 方法")
        x = 'hello'
        assert 'e' in x

  • 用法1:-k “類名”—>表示任意位置模糊匹配類名的所有類,并執(zhí)行匹配到的這些類的所有方法
-k "TestDemo1"

-k "Test"

  • 這里會運行所有以test開頭的方法(即test_a,test_one,test_two,test_three,test_one,test_o2,test_3),運行截圖如下:

    [
    image

    image853×306 8.35 KB](https://ceshiren.com/uploads/default/original/2X/e/e1f6d3c260d92824b6fa571007c6938cc7c4cf5d.png)

  • 用法3:-k “類名 and not 方法名”—>表示任意位置模糊匹配類名的所有類,并執(zhí)行匹配到的這些類的所有方法,但不會執(zhí)行任意位置模糊匹配的方法;如果多個類都有個指定的這個方法,則所有類中的這個方法都不會執(zhí)行

-k "TestDemo and not test_o"

(文章來源于霍格沃茲測試學(xué)院)

更多技術(shù)文章可點擊http://qrcode.testing-studio.com/f?from=jianshu&url=https://ceshiren.com/t/topic/3822

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容