开发者

How to check for instantiation of a python class during unit-tests

I 开发者_如何学Pythonfor the life of me can not remember how to test for the instination of a python class.

It was something like:

try:
  m = MyModel()
except:
  ...

I can't remember the exception to call or the assert to use.


There is no common exception to use for failed instantiation. The constructor (both __init__ and __new__) can raise any exception it wants. The except statement you have without an explicit exception will catch every type of exception, which may be what you want.


I'm not exactly sure what you are asking, however here is a list of all built in exceptions for Python (2.7):

http://docs.python.org/library/exceptions.html

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜