如何在使用py.test时显示为什么跳过某些测试?

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


lmi*_*asf 7

简短的回答:

pytest -rs
Run Code Online (Sandbox Code Playgroud)

这将显示跳过测试的额外信息。

详细解答:

为了补充@ToddWilson 的回答,添加了以下字符:pP( 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