python中是否有任何断言语句来检查是否没有引发任何异常?

原文标题Is there any assert statement in python to check if there is no raise of any exception?

正如我们在python中所知道的,我们使用assert。Raises来检查异常情况,同样有没有与之相反的assert语句?就像通过场景测试用例不会引发任何异常。我在网上查过没有得到正确的答案,我是python的新手,在此先感谢

原文链接:https://stackoverflow.com//questions/71463272/is-there-any-assert-statement-in-python-to-check-if-there-is-no-raise-of-any-exc

回复

我来回复
  • wogsland的头像
    wogsland 评论

    是的,例如,如果您使用 unittest 进行测试,则有 assertRaises()。如果您使用 pytest 进行测试,那么有 israises()。

    2年前 0条评论