gpt4 book ai didi

unit-testing - py.test : dump stuck background threads at the end of the tests

转载 作者:行者123 更新时间:2023-12-01 12:38:05 24 4
gpt4 key购买 nike

我正在使用 pytest 运行我的项目 Python 单元测试。

由于某种原因,有时在打印测试统计信息后测试运行程序不存在。我怀疑这是因为一些测试打开了后台线程,而一些悬空线程在拆解时没有正确清理。由于这种情况并非每次都发生,因此更难确定到底发生了什么。

我希望找到一种方法让 pytest 在打印失败并通过测试后显示哪些线程。我想出了一些想法?

  • 测试完成后运行自定义 Hook - py.test 是否支持任何此类 Hook ?
  • 其他方式(自定义 py.test 包装脚本)

  • 我认为其他替代方法只是在每次拆卸结束时打印线程转储。

    python 3.4。

    最佳答案

    尝试使用 pytest-timeout plugin... 发生超时后,它将转储所有线程并退出进程。

    如果您想自己实现自定义代码,请查看 pytest hooks .我想你可以使用 pytest_runtest_teardown钩子(Hook)来编写自定义拆解代码。

    关于unit-testing - py.test : dump stuck background threads at the end of the tests,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27736697/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com