A problem with assertRaises function in Python

Posted by anton.k. on Stack Overflow See other posts from Stack Overflow or by anton.k.
Published on 2010-05-25T11:23:00Z Indexed on 2010/05/25 11:31 UTC
Read the original article Hit count: 247

Filed under:
|

Hello,guys! I am trying to run the following test

 self.assertRaises(Exception,lambda:
 unit_test.testBasic())

where

test.testBasic()

is

class IsPrimeTest(unittest.TestCase):
    def assertRaises(self,exception,callable,*args,**kwargs):
        print('dfdf')
        temp = callable
        super().assertRaises(exception,temp,*args,**kwargs)

   def testBasic_helper(self):

        self.failIf(is_prime(2))
        self.assertTrue(is_prime(1))

where prime is a function,and

but in

self.assertRaises(Exception,lambda:
unit_test.testBasic())

the lambda function doesnt throws an exception after the test

def testBasic_helper(self):

   self.failIf(is_prime(2))
   self.assertTrue(is_prime(1))

fails Can somebody offers a solution to the problem?

© Stack Overflow or respective owner

Related posts about python

Related posts about assertraises