Python 如何显示在使用py.test时跳过某些测试的原因?

Python 如何显示在使用py.test时跳过某些测试的原因?,python,unit-testing,pytest,Python,Unit Testing,Pytest,我正在使用unittest中的skipIf()跳过特定条件下的测试 @unittest.skipIf(condition), "this is why I skipped them!") 如何告诉py.test显示跳过条件 我知道,对于unittest,我需要启用详细模式(-v),但添加到py.test的相同参数增加详细度,但仍然不会显示跳过原因。运行py.test时,可以通过-rsx报告跳过的测试 从py.test--help: -r chars show extra

我正在使用
unittest
中的
skipIf()
跳过特定条件下的测试

@unittest.skipIf(condition), "this is why I skipped them!")
如何告诉
py.test
显示跳过条件


我知道,对于unittest,我需要启用详细模式(
-v
),但添加到py.test的相同参数增加详细度,但仍然不会显示跳过原因。

运行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.

另请参阅有关跳过的文档的这一部分:

简短回答:

pytest -rs
这将显示跳过测试的额外信息

详细答案:

pytest -rs
为了补充@ToddWilson的答案,添加了以下字符:
p
p
(),
a
()和
a
()。默认情况下,不会显示有关跳过和失败测试的详细信息,以避免输出混乱。您可以将标志与以下字符一起使用:

  • f
    )故障
  • E
    )错误
  • s
    )kipped
  • x
    )失败
  • X
    )已通过
  • p
    )已批准
  • P
    )与输出一致
  • a
    )除通过(p/p)外,其余均为ll
  • A
    )ll
默认情况下会启用警告,默认值为
fE