I am writing a program in python and one of my methods should take in a string, and if that string is not of desired length, I want it to raise an exception and pass the corresponding unittest without throwing errors in the console.
Method:
def validate_length(guess):.
if len(guess) != 5:
raise Exception("Invalid guess length")
Unittest:
@parameterized.expand([
("FOR"),
("FERVER"),
])
def test_for_wrong_word_length(self, guess):
self.assertRaises(Exception, tally("FAVOR", guess))
Output:
Exception: Invalid guess length
Exception: Invalid guess length
FAILED (errors=2)
I want this to give me the status 'OK' rather than 'FAILED (errors=2).' Everything I have read on unittest documentation shows that it should pass this way, but I can't figure out why.
Also, I have my files set up correctly and imports, etc. These blocks above are just snippets. I have other tests working properly.