How can you use the unittest framework to confirm that a specific exception is raised by a piece of code?

  • Use assertException() method
  • Use assertRaises() method
  • Use checkException() method
  • Use expectException() method
In unittest, you can use the assertRaises() method to confirm that a specific exception is raised by a piece of code. This method takes the exception class and the callable as arguments and asserts that the callable raises the specified exception.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *