pytest打印语​​句仅在退出()之前发出时才有效[重复]

Posted

技术标签:

【中文标题】pytest打印语​​句仅在退出()之前发出时才有效[重复]【英文标题】:pytest print statements only work when issued before quit() [duplicate] 【发布时间】:2021-11-13 23:20:04 【问题描述】:

我有一个如下所示的 pytest 类:

class TestModule:

    def test_print(self):
        print("test")

此测试仅通过,不打印任何内容。

    def test_print(self):
        print("test")
        quit()

这会打印测试然后引发。这有什么原因吗?如何在 pytest 中打印到标准输出?

【问题讨论】:

【参考方案1】:

打印语句显示是否在运行时添加 -s 标志

【讨论】:

以上是关于pytest打印语​​句仅在退出()之前发出时才有效[重复]的主要内容,如果未能解决你的问题,请参考以下文章