gpt4 book ai didi

python - 测试失败的 ndb 事务

转载 作者:行者123 更新时间:2023-11-28 16:42:21 25 4
gpt4 key购买 nike

我想对从模型调用 put 函数时如果 ndb 中的事务失败会发生什么进行单元测试。
是否有可能故意使交易失败?

最佳答案

来自docs :

If the function raises an exception, the transaction is immediately aborted and NDB re-raises the exception so that the calling code sees it. You can force a transaction to fail silently by raising the ndb.Rollback exception (the function call returns None in this case). There is no mechanism to force a retry.

您可以在单元测试而不是 put() 例程中引发异常来模拟该事件,它应该模拟相同的结果 - 因为 put 失败将导致事务中的所有数据存储事件无论如何都会回滚。

您可能会找到 these kinds交易异常:

You can receive Timeout, TransactionFailedError, or InternalError exceptions in cases where transactions have been committed and eventually will be applied successfully.

关于python - 测试失败的 ndb 事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17743367/

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