
March 31, 2020
10:02 a.m.
But if you use a context manager which silences the exception, like contextlib.suppress() or unittest.TestCase.assertRaises(), it is easy to do too.
was_not_raised = False with my_context(): do_something_sensitive() was_not_raised = True if was_not_raised: print("We're all safe.")
That is indeed a way to workaround my use case. I do still find a with/else more elegant.