I'm trying to add some unit tests to make sure that the correct Error is being thrown (my function either throws KeyError
or RuntimeError
).
I've tried assert func(bad_param) == KeyError
and assert isinstance(func(bad_param), KeyError)
but neither of these are correct, how am I supposed to write unit tests for this / what's the correct way to assert that this function, when passed a bad parameter, will raise the correct Exception?
EDIT: I'm NOT using the unittest
library, I'm asking about purely the assert
function that comes with Python std lib (https://docs.python.org/3/reference/simple_stmts.html)