How to properly use unit-testing’s assertRaises() with NoneType objects? [duplicate]

I did a simple test case:

def setUp(self):

  self.testListNone = None

def testListSlicing(self):

  self.assertRaises(TypeError, self.testListNone[:1])

and I am expecting test to pass, but I am getting exception:

Traceback (most recent call last):

    self.assertRaises(TypeError, self.testListNone[:1])

TypeError: 'NoneType' object is unsubscriptable

I thought that assertRaises will pass since TypeError exception will
be raised?

4 Answers
4

Leave a Comment