|
41 | 41 | import tempfile |
42 | 42 | from test.script_helper import assert_python_ok |
43 | 43 | from test.support import (captured_stdout, run_with_locale, run_unittest, |
44 | | - patch, requires_zlib, TestHandler, Matcher, HOST) |
| 44 | + patch, requires_zlib, TestHandler, Matcher, HOST, |
| 45 | + swap_attr) |
45 | 46 | import textwrap |
46 | 47 | import time |
47 | 48 | import unittest |
@@ -3748,18 +3749,12 @@ def test_exception(self): |
3748 | 3749 | (exc.__class__, exc, exc.__traceback__)) |
3749 | 3750 |
|
3750 | 3751 | def test_log_invalid_level_with_raise(self): |
3751 | | - old_raise = logging.raiseExceptions |
3752 | | - self.addCleanup(setattr, logging, 'raiseExecptions', old_raise) |
3753 | | - |
3754 | | - logging.raiseExceptions = True |
3755 | | - self.assertRaises(TypeError, self.logger.log, '10', 'test message') |
| 3752 | + with swap_attr(logging, 'raiseExceptions', True): |
| 3753 | + self.assertRaises(TypeError, self.logger.log, '10', 'test message') |
3756 | 3754 |
|
3757 | 3755 | def test_log_invalid_level_no_raise(self): |
3758 | | - old_raise = logging.raiseExceptions |
3759 | | - self.addCleanup(setattr, logging, 'raiseExecptions', old_raise) |
3760 | | - |
3761 | | - logging.raiseExceptions = False |
3762 | | - self.logger.log('10', 'test message') # no exception happens |
| 3756 | + with swap_attr(logging, 'raiseExceptions', False): |
| 3757 | + self.logger.log('10', 'test message') # no exception happens |
3763 | 3758 |
|
3764 | 3759 | def test_find_caller_with_stack_info(self): |
3765 | 3760 | called = [] |
|
0 commit comments