I've used it before to validate that some inputs are correct, for example, if the number for "fingers" from class Hands is negative, then an exception is thrown:
self.assertRaises(ValueError, hands.Hands, fingers = -1)
The test passes, because the exception was thrown!
Fingers is a parameter in the constructor for hands.
My problem now is that I want to check to see if an exception is thrown in another method in class Hand, outside of the constructor. Let's say I have a method called numOfHands(num). If you have some sort of defect or for medical reasons lost a hand, you could have 0, 1, or 2. Anything greater than 2 would yield an exception for "ValueError: too many hands!"
However, I don't think that assertRaises handles methods. If I try this:
handTest = Hands() #creates constructor self.assertRaises(ValueError, hands.Hands, handTest.numOfHands(3))
I get the traceback "ValueError: too many hands!" printed out, but assertRaises doesn't catch it, and my test fails.
Does anyone know of another test to make this work, or how to make the formatting work?