sor*_*rin 37 python unit-testing pytest
我使用skipIf()从unittest跳过在一定条件下的测试.
@unittest.skipIf(condition), "this is why I skipped them!")
Run Code Online (Sandbox Code Playgroud)
如何判断py.test显示跳过条件?
我知道对于unittest我需要启用详细模式(-v)但是添加到py.test的相同参数增加了详细程度仍然不显示跳过原因.
小智 56
运行py.test时,可以传递-rsx报告跳过的测试.
来自py.test --help:
-r chars show extra test summary info as specified by chars
(f)ailed, (E)error, (s)skipped, (x)failed, (X)passed.
Run Code Online (Sandbox Code Playgroud)
另请参阅有关跳过的文档的这一部分:http://pytest.org/latest/skipping.html
简短的回答:
pytest -rs
Run Code Online (Sandbox Code Playgroud)
这将显示跳过测试的额外信息。
详细解答:
为了补充@ToddWilson 的回答,添加了以下字符:p和P( 2.9.0 )、a( 4.1.0 ) 和A( 4.5.0 )。为了避免混乱输出,默认情况下不显示有关跳过和 xfailed 测试的详细信息。您可以-r在以下字符中使用该标志:
f) 生病E) 错误s) 跳过x)失败X)通过p) 评估P) 评估输出a)ll 除了通过 (p/P)A)ll。默认情况下启用警告,默认值为fE。