0
点赞
收藏
分享

微信扫一扫

pytest -k 参数的用法—笔记

Sophia的玲珑阁 2021-09-30 阅读 43
日记本

-k参数的用法,示例代码如下:

def test_a():
    print("test_a")

class TestDemo():

    def test_one(self):
        print("开始执行 test_one 方法")
        x = 'this'
        assert 'h' in x

    def test_two(self):
        print("开始执行 test_two 方法")
        x = 'hello'
        assert 'e' in x

    def test_three(self):
        print("开始执行 test_three 方法")
        a = 'hello'
        b = 'hello world'
        assert a not in b

class TestDemo1():
    def test_one(self):
        print("开始执行 test_one 方法")
        a = 'hello'
        b = 'hello world'
        assert a not in b

    def test_o2(self):
        print("开始执行 test_o2 方法")
        x = 'this'
        assert 'h' in x

    def test_3(self):
        print("开始执行 test_3 方法")
        x = 'hello'
        assert 'e' in x

  • 用法1:-k “类名”—>表示任意位置模糊匹配类名的所有类,并执行匹配到的这些类的所有方法
-k "TestDemo1"

-k "Test"

  • 这里会运行所有以test开头的方法(即test_a,test_one,test_two,test_three,test_one,test_o2,test_3),运行截图如下:

    [

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

  • 用法3:-k “类名 and not 方法名”—>表示任意位置模糊匹配类名的所有类,并执行匹配到的这些类的所有方法,但不会执行任意位置模糊匹配的方法;如果多个类都有个指定的这个方法,则所有类中的这个方法都不会执行

-k "TestDemo and not test_o"

(文章来源于霍格沃兹测试学院)

更多技术文章可点击http://qrcode.testing-studio.com/f?from=jianshu&url=https://ceshiren.com/t/topic/3822

举报

相关推荐

0 条评论