Mike Ramirez
Mike Ramirez

Reputation: 10970

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

I for 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.

Upvotes: 3

Views: 824

Answers (2)

dappawit
dappawit

Reputation: 12570

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.

Upvotes: 1

Mike Lewis
Mike Lewis

Reputation: 64137

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.

Upvotes: 0

Related Questions