[英]Test for 'ExceptionError' with py.test
您好,我有一个类对象骰子,最终将其自身删除。 使用py.test如何使py.test返回正向删除对象的对象?
我试过了,但这是语法错误:
assert dice raises(ExceptionError)
谢谢。
您可以检查globals()。 它包含所有全局变量。
if "dice" in globals():
do something
else:
raise(Exception)
使用pytest,测试像这样的预期错误
import pytest
with pytest.raises(ZeroDivisionError):
1 / 0
这是docs章节有关预期异常的断言中的示例
在你的情况下会是这样的
import pytest
with pytest.raises(ExceptionError)
# Instantiate a dice object
# Do stuff that makes it delete itself
在这里,我使用了您自己命名的错误,我不知道这是否是引发的实际错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.