Feb-25-2024, 11:54 AM
hi
I have the two below codes:
the below error was appeared:
thanks
I have the two below codes:
#one.py def add(x,y): return x+y def subtract(x,y) : return x-y def multiply(x,y): return x*y def division(x,y) : if y==0 : raise ZeroDIvisionErorr ("can't division by zero...") return x/y and the below test_one.py:#test_one.py ''' for test one.py with using unittest. ''' import unittest import one class oneTest(unittest.TestCase): def test_add(self): self.assertEqual(one.add(4,5),9) self.assertEqual(one.add(-1,4),3) def test_subtract(self): self.assertEqual(one.subtract(5,0),5) def test_multiply(self): self.assertEqual(one.multiply(4,5),20) self.assertEqual(one.multiply(7,0),0) def test_division(self): self.assertEqual(one.division(30,5),6) self.assertRaises(ZeroDivisionError,one.division,4,0) if __name__=='__main__' : unittest.mainafter that, when I wrote in cmd: D:\Desktop\pypypy>python -m unittest test_one.py
the below error was appeared:
Error:.E.. ====================================================================== ERROR: test_division (test_one.oneTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\Desktop\pypypy\test_one.py", line 23, in test_division self.assertRaises(ZeroDivisionError,one.division,4,0) File "C:\Program Files (x86)\Thonny\lib\unittest\case.py", line 738, in assertRaises return context.handle('assertRaises', args, kwargs) File "C:\Program Files (x86)\Thonny\lib\unittest\case.py", line 201, in handle callable_obj(*args, **kwargs) File "D:\Desktop\pypypy\one.py", line 12, in division raise ZeroDIvisionErorr ("can't division by zero...") NameError: name 'ZeroDIvisionErorr' is not defined ---------------------------------------------------------------------- Ran 4 tests in 0.004s FAILED (errors=1) D:\Desktop\pypypy>'''what is the problem?thanks
