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.
Loading...
Related Quiz
- To create a tuple with a single item, you need to add a _______ after the item.
- If you want to overload the less than (<) operator for a class, you will define the _______ method in your class.
- The ____ function in Python’s time module can be used to measure the elapsed time and is useful for profiling.
- How would you create an instance of a metaclass in Python?
- In Python, the operator == checks for _______.