I want to unittest an exception handling in my unittest and I'm using assertRaises to check if exception is thrown.
class Add():
def __init__(self, x, y):
if type(x) != int or type(y) != int:
raise Exception('Not a valid number')
Add(None, None)
import unittest
from test2 import Add
class TestAdd(unittest.TestCase):
def test_check_for_valid_nos(self):
self.assertRaises(Exception, Add(None,None))
if __name__ == '__main__':
unittest.main()
When I run this piece of code it still raises exception. I expect the test to pass saying that the exception has been raised.
Add(None, None)line?