diff -r 0220328f962c Lib/test/test_logging.py --- a/Lib/test/test_logging.py Mon Jul 20 17:44:59 2015 -0400 +++ b/Lib/test/test_logging.py Tue Jul 21 21:26:19 2015 +0200 @@ -41,7 +41,8 @@ import tempfile from test.script_helper import assert_python_ok from test.support import (captured_stdout, run_with_locale, run_unittest, - patch, requires_zlib, TestHandler, Matcher, HOST) + patch, requires_zlib, TestHandler, Matcher, HOST, + swap_attr) import textwrap import time import unittest @@ -3748,18 +3749,12 @@ (exc.__class__, exc, exc.__traceback__)) def test_log_invalid_level_with_raise(self): - old_raise = logging.raiseExceptions - self.addCleanup(setattr, logging, 'raiseExecptions', old_raise) - - logging.raiseExceptions = True - self.assertRaises(TypeError, self.logger.log, '10', 'test message') + with swap_attr(logging, 'raiseExceptions', True): + self.assertRaises(TypeError, self.logger.log, '10', 'test message') def test_log_invalid_level_no_raise(self): - old_raise = logging.raiseExceptions - self.addCleanup(setattr, logging, 'raiseExecptions', old_raise) - - logging.raiseExceptions = False - self.logger.log('10', 'test message') # no exception happens + with swap_attr(logging, 'raiseExceptions', False): + self.logger.log('10', 'test message') # no exception happens def test_find_caller_with_stack_info(self): called = []