【发布时间】:2021-12-25 05:34:49
【问题描述】:
这是我的代码
在module.py中:
def myFunc():
print('aaa')
在 test_module.py 中:
def test_myFunc():
print('bbb')
myFunc()
如果我运行pytest -s test_module.py,那么我可以看到打印输出bbb;但我看不到打印输出aaa。
其实我也试过import logging来玩logger,也没有运气。
所以基本上我的问题是,在触发pytest 时,我们如何从 src 代码中看到打印输出?
【问题讨论】:
-
Pytest 拦截打印和日志记录。它们只会在失败时显示。这样应用程序就不会弄乱 pytest 的输出。有命令行参数可以改变行为。
-
实际上
pytest -s应该这样做,因为它禁用捕获输出 - 我怀疑环境中还有其他事情发生(配置,插件,...)。跨度> -
如果没有进一步的信息,这个问题就无法回答,就像给定的例子一样。
-
我无法重现,你在用
capsys/capfd吗?