如何在 Plone 上打印测试中的内容
我正在使用 plone.app.testing 编写一些集成测试。
有时我想在控制台上打印一些东西,但在我看来,只有当特定测试完成时,东西才会打印在控制台上。
plone.app.testing 或后面的某些软件包是否有一些我可以使用的日志记录工具?
I'm writing some integration test with plone.app.testing.
Sometimes I want to print something to the console, but it seems to me that stuff gets printed on the console only when a particular test has finished.
Does plone.app.testing or some of the packages behind have some logging facility which I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了支持测试日志输出,IOW 测试检查您的代码是否按应有的方式记录内容,我认为 zope.testing 会拦截所有日志记录。此外,根据您的测试方式,stdout 可能会被替换或拦截,例如 doctests,因此打印到 stdout 可能也不起作用。
就我个人而言,我使用了 pdb.set_trace() 或者我暂时强制失败,IOW 没有提交它,此时我想使用 "-D" 用于 pdb.post_mortem() 调试。
但是,您可以使用 zope.testing.loggingsupport 来收集你想要的信息,然后你可以使用 pdb.set_trace() 或 "-D" 来获取 pdb 提示符,您可以在其中检查您创建的用于捕获日志记录输出的任何处理程序。
To support testing logging output, IOW tests that check that your code is logging things as it should, I think zope.testing intercepts all logging. Additionally, depending on how you're testing, stdout may be replaced or intercepted, as with doctests for example, so printing to stdout may not work either.
Personally, I used pdb.set_trace() or I force a failure temporarily, IOW without committing it, at the point I want to inspect and run the tests with "-D" for pdb.post_mortem() debugging.
You may, however, be able to make some use of zope.testing.loggingsupport to collect the information you want and then you can use a pdb.set_trace() or "-D" to get a pdb prompt at which you can inspect whatever handler you created to capture logging output.
也看看这个: 将日志输出重定向到测试中的 sys.stdout。
Take a look on this also: Redirecting log output to sys.stdout on tests.