-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),运行截图如下:
[image837×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),运行截图如下:
[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"
-
这里会运行类TestDemo,TestDemo1下的,除了test_o**以外的所有方法(即test_two,test_three,test_3),运行截图如下:
[image857×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