You need try-finally here. If the assertRaises fails restore part of the method is skipped.