Skip to content
Advertisement

Python Unittest Allow Multiple Possible Return Values

I’m writing a unittest that will be run on my class’s code. For one of the functions they must write, there are two possible return values that they could return and either one is okay for my purposes.

I’ve been using

JavaScript

But this doesn’t work for accepting one of two valid return values, so I’ve changed it to:

JavaScript

Is there a way to do this that isn’t as hacky?

Advertisement

Answer

There exists assertIn test, which you could use in this case as follows

JavaScript

it does check if actual is present in list holding expected1,expected2.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement