From: Oti <oh...@ya...> - 2004-02-10 21:28:53
|
[ jai ] > import com.ml.dhi.vo.ArchivedDevicesVO > import unittest > > class jython_Archive(unittest.TestCase): > > def testNormalCase(self): obj=com.ml.dhi.vo.ArchivedDevicesVO("one","t","th","fo","f","si","sev","eig" > ); > obj.init() > obj.setBuilding("abc") > self.assertEqual(obj.getBuilding(),"abc") > > def testFailCase(self): > self.assertRaises(TypeError,obj.setBuilding) > self.assertRaises(TypeError,obj.setBuilding, > 'one','another') > > The erros msg is > Traceback (most recent call last): > File "jython_Archive.py", line 22, in testFailCase > self.assertRaises(TypeError,obj.setBuilding) > NameError: obj obj is a local variable in method testNormalCase(), and cannot be accessed from method testFailCase(). If you want to share variables, use instance variables. A good place to initialize them is in method setUp(): import com.ml.dhi.vo.ArchivedDevicesVO import unittest class jython_Archive(unittest.TestCase): def setUp(self): self.obj = com.ml.dhi.vo.ArchivedDevicesVO(...) self.obj.init() def testNormalCase(self): self.obj.setBuilding("abc") self.assertEqual(self.obj.getBuilding(),"abc") def testFailCase(self): self.assertRaises(TypeError,self.obj.setBuilding) self.assertRaises(TypeError, self.obj.setBuilding, 'one', 'another') # i think you would need () after self.obj.setBuilding ? Best wishes, Oti. |