参数名 | 参数解释 | 备注 |
---|---|---|
-h | 查看 pytest 的所有选项 | |
-q | 简化输出结果 | 静默运行,不输出执行过程,只输出结果 |
-v | 等价于 verbose=True,也就是说输出详细信息 | |
-s | 允许终端在测试运行时输出某些结果,例如你想输入print的内容,可以加上-s | |
-k | -K EXPRESSION | 执行某个关键字的用例 用例要匹配给出的表达式;使用python的语法,匹配的范围是文件名、类名、函数名为变量,用and来区分 |
-m 标签1 or 标签2 | 运行多个标签以或的形式 | |
-m 标签1 and 标签2 | 运行多个标签以并且的形式,也就是说的你的统一模块上必须同时包含两个标签名,否则将不被选中 |
-k 实际用法
# content of test.py
class TestClass(object):
def test_zne(self):
x = "this"
assert 'h' in x
def test_two(self):
x = "hello"
assert hasattr(x, 'check')
def test_a(self):
assert 1==2
运行参数 pytest -k "test and TestClass and not test_a" test.py
参数解释 执行test文件下 TestClass类中,不包含 test_a 的测试用例