This question already has an answer here:
- Python:How to use nose's assert_raises? 2 answers
Beginner here working on a LPTHW. I am writing a unit test and cannot figure out the syntax for "assert_raises"
For exampe in this bit of code here:
def parse_subject(word_list):
skip(word_list, 'stop')
next_word = peek(word_list)
if next_word == 'noun':
return match(word_list, 'noun')
elif next_word == 'verb':
return ('noun', 'player')
else:
raise ParserError("Expected a verb next.")
I don't know how to write a successful test for when "Expected a verb next." is returned. I've had success using assert_equals, but what is the equivalent of assert_equals for when an Error is raised. I know the function is assert_raises, but don't know the syntax. I hope this makes sense, any help would be appreiated. Thanks!
Aucun commentaire:
Enregistrer un commentaire