dimanche 4 octobre 2015

Unittesting in Python, How do I check for custom error Message

I am trying to right a test case which passes if an error is raised. Though the class raises custom error.

Below is the error as raised in the original class.

else:
            raise MultipleObjectsReturned("Multiple videos met this criteria.")

Now When I try to catch it, it return error.

def test_get(self):

        with self.assertRaises('MultipleObjectsReturned'):
            self.yt.get()

Error:

 File "C:\Python27\lib\unittest\case.py", line 117, in __exit__
    if not issubclass(exc_type, self.expected):
TypeError: issubclass() arg 2 must be a class or tuple of classes

How can I make it catch custom error messages.

Aucun commentaire:

Enregistrer un commentaire