We need to do a unit test for the exception
Is there a way to deliberately cause specific exceptions such as EOFError and ZeroDivisionError?
In the unittest module, You must write TestCase.assertRaises().
For example,
import mymod
class MyTestCase(unittest.TestCase):
def test1(self):
self.assertRaises(ZeroDivisionError, mymod.myfunc)
Together
If a function receives a factor,
self.assertRaises(ZeroDivisionError, mymod.myfunc, arg1, arg2)
You can pass the factor as shown in .
© 2026 OneMinuteCode. All rights reserved.