the __exit__()
method should accept information about exceptions that come up in the with:
block. See here.
The following modification of your code works:
def __exit__(self, exc_type, exc_value, tb):
if exc_type is not None:
traceback.print_exception(exc_type, exc_value, tb)
# return False # uncomment to pass exception through
return True
Then you can try raising an exception in one of your with:
blocks and it'll be caught in __exit__()
.