简体   繁体   English

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

[英]How to I display why some tests where skipped while using py.test?

I am using skipIf() from unittest for skipping tests in certain conditions.我正在使用unittest skipIf()在某些条件下跳过测试。

@unittest.skipIf(condition), "this is why I skipped them!")

How do I tell py.test to display skipping conditions?如何告诉py.test显示跳过条件?

I know that for unittest I need to enable the verbose mode ( -v ) but the same parameter added to py.test increase the verbosity by still does not display the skip reasons.我知道对于 unittest 我需要启用详细模式( -v )但是添加到 py.test 的相同参数增加了详细程度仍然不显示跳过原因。

When you run py.test, you can pass -rsx to report skipped tests.当你运行 py.test 时,你可以通过-rsx来报告跳过的测试。

From py.test --help :py.test --help

-r chars            show extra test summary info as specified by chars
                    (f)ailed, (E)error, (s)skipped, (x)failed, (X)passed.

Also see this part of the documentation about skipping: http://doc.pytest.org/en/latest/skipping.html另请参阅有关跳过的文档的这一部分: http : //doc.pytest.org/en/latest/skipping.html

Short answer:简短的回答:

pytest -rs

This will show extra information of skipped tests.这将显示跳过测试的额外信息。

Detailed answer:详细解答:

To complement @ToddWilson's answer, the following chars have been added: p and P ( 2.9.0 ), a ( 4.1.0 ) and A ( 4.5.0 ).为了补充@ToddWilson 的回答,添加了以下字符: pP ( 2.9.0 )、 a ( 4.1.0 ) 和A ( 4.5.0 )。 The detailed information about skipped and xfailed tests is not shown by default in order to avoid cluttering the output.为了避免混乱输出,默认情况下不显示有关跳过和 xfailed 测试的详细信息。 You can use the -r flag among with the following chars:您可以在以下字符中使用-r标志:

  • ( f )ailed ( f ) 失败
  • ( E )rror ( E ) 错误
  • ( s )kipped ( s ) 跳过
  • ( x )failed ( x ) 失败
  • ( X )passed ( X ) 通过
  • ( p )assed ( p ) 评估
  • ( P )assed with output ( P ) 评估输出
  • ( a )ll except passed (p/P) ( a )ll 除了通过 (p/P)
  • ( A )ll. ( A )ll。

Warnings are enabled by default, and the default value is fE .默认情况下启用警告,默认值为fE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM