Possible Duplicate:
How do you test that a Python function throws an exception?
I have to do white-box and black-box testing so i`m wondering how it is possible to test a function that trows an exceptions, like this one
class validator_client():
def validate_client(self,client):
erori=[]
if client.get_identitate()=="":
erori.append("Nu exista ID!")
if client.get_nume()=="":
erori.append("Nu exista nume!")
if (client.get_filme_inchiriate()!="da" ) and (client.get_filme_inchiriate()!="nu") :
erori.append("Campul 'Filme inchiriate' completat gresit!")
if len(erori)>0:
raise ValidatorException(erori)
I`ve read something about assertRises() but i can not import the module with this method, found this on stackowerflow:
from testcase import TestCase
import mymod
class MyTestCase(TestCase):
def test1(self):
self.assertRaisesWithMessage(SomeCoolException,
'expected message',
mymod.myfunc)
but I`m not able to make it work.