-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"
-
這里會運行TestDemo1類下的所有方法(即test_one,test_o2,test_3),運行截圖如下:
[imageimage837×227 6.91 KB](https://ceshiren.com/uploads/default/original/2X/9/9bd7d62281199b9e8cde1959a3a5d26b3c812133.png)
用法2:-k “方法名”—>表示任意位置模糊匹配方法名的所有方法,并執行匹配到的這些方法
-k "Test"
-
這里會運行所有以test開頭的方法(即test_a,test_one,test_two,test_three,test_one,test_o2,test_3),運行截圖如下:
[imageimage853×306 8.35 KB](https://ceshiren.com/uploads/default/original/2X/e/e1f6d3c260d92824b6fa571007c6938cc7c4cf5d.png)
用法3:-k “類名 and not 方法名”—>表示任意位置模糊匹配類名的所有類,并執行匹配到的這些類的所有方法,但不會執行任意位置模糊匹配的方法;如果多個類都有個指定的這個方法,則所有類中的這個方法都不會執行
-k "TestDemo and not test_o"
-
這里會運行類TestDemo,TestDemo1下的,除了test_o**以外的所有方法(即test_two,test_three,test_3),運行截圖如下:
[imageimage857×237 7.65 KB](https://ceshiren.com/uploads/default/original/2X/9/928c014f32fc71f22b57476832a3c14a8ec1f243.png)
說明:不區分大小寫
(文章來源于霍格沃茲測試學院)
更多技術文章可點擊http://qrcode.testing-studio.com/f?from=jianshu&url=https://ceshiren.com/t/topic/3822