Testing fail() scenarii in plain starlark functions using the unittest library is not supported out of the box and requires wrapping the function into a rule and creating an analysis test for it.
This post was very helpful in showing how to achieve that, and it would be great to add that somewhere in the docs (e.g. with a link to an example).