diff -r 42bfb4b48101 Lib/distutils/tests/support.py --- a/Lib/distutils/tests/support.py Thu Nov 12 13:28:07 2015 +0200 +++ b/Lib/distutils/tests/support.py Thu Nov 12 14:21:55 2015 +0200 @@ -10,6 +10,15 @@ from copy import deepcopy from distutils import log from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL from distutils.core import Distribution +import contextlib + + +@contextlib.contextmanager +def restore_log_level(): + threshold = log.set_threshold(log.WARN) + log.set_threshold(threshold) + yield threshold + log.set_threshold(threshold) class LoggingSilencer(object): diff -r 42bfb4b48101 Lib/distutils/tests/test_core.py --- a/Lib/distutils/tests/test_core.py Thu Nov 12 13:28:07 2015 +0200 +++ b/Lib/distutils/tests/test_core.py Thu Nov 12 14:21:55 2015 +0200 @@ -116,14 +116,14 @@ class CoreTestCase(support.EnvironGuard, def test_debug_mode(self): # this covers the code called when DEBUG is set sys.argv = ['setup.py', '--name'] - with captured_stdout() as stdout: + with captured_stdout() as stdout, support.restore_log_level(): distutils.core.setup(name='bar') stdout.seek(0) self.assertEqual(stdout.read(), 'bar\n') distutils.core.DEBUG = True try: - with captured_stdout() as stdout: + with captured_stdout() as stdout, support.restore_log_level(): distutils.core.setup(name='bar') finally: distutils.core.DEBUG = False diff -r 42bfb4b48101 Lib/distutils/tests/test_dist.py --- a/Lib/distutils/tests/test_dist.py Thu Nov 12 13:28:07 2015 +0200 +++ b/Lib/distutils/tests/test_dist.py Thu Nov 12 14:21:55 2015 +0200 @@ -409,7 +409,7 @@ class MetadataTestCase(support.TempdirMa sys.argv = [] dist.help = 1 dist.script_name = 'setup.py' - with captured_stdout() as s: + with captured_stdout() as s, support.restore_log_level(): dist.parse_command_line() output = [line for line in s.getvalue().split('\n') diff -r 42bfb4b48101 Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py Thu Nov 12 13:28:07 2015 +0200 +++ b/Lib/test/test_shutil.py Thu Nov 12 14:21:55 2015 +0200 @@ -1037,7 +1037,7 @@ class TestShutil(unittest.TestCase): # now create another tarball using `tar` tarball2 = os.path.join(root_dir, 'archive2.tar') tar_cmd = ['tar', '-cf', 'archive2.tar', base_dir] - with support.change_cwd(root_dir), captured_stdout(): + with support.change_cwd(root_dir): spawn(tar_cmd) self.assertTrue(os.path.isfile(tarball2))