jeudi 1 janvier 2015

In python 3.4.1, how can I assert an error in unittest like this?

For example, I define a function like



def f(n): return 1+'1'


and in the unittest, I define test_error:



assertRaises(TypeError,f(1))


But it just showed that this is a error. But when I define f with no argument like



def f(): return 1+'1'


and in unittest



assertRaises(TypeError,f)


it worked just fine. Why is that? How can I deal with function with arguments?


Aucun commentaire:

Enregistrer un commentaire