From: Victor Stinner Date: Tue, 29 Mar 2016 23:15:28 +0000 (+0200) Subject: Fix ResourceWarning in test_unittest when interrupted X-Git-Tag: v3.6.0a1~302^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9db2ae7263d8047c29a13ad476534a4cbcdbd8f6;p=python Fix ResourceWarning in test_unittest when interrupted --- diff --git a/Lib/unittest/test/test_runner.py b/Lib/unittest/test/test_runner.py index 9cbc26041f..ddc498c230 100644 --- a/Lib/unittest/test/test_runner.py +++ b/Lib/unittest/test/test_runner.py @@ -290,7 +290,8 @@ class Test_TextTestRunner(unittest.TestCase): # no args -> all the warnings are printed, unittest warnings only once p = subprocess.Popen([sys.executable, '_test_warnings.py'], **opts) - out, err = get_parse_out_err(p) + with p: + out, err = get_parse_out_err(p) self.assertIn(b'OK', err) # check that the total number of warnings in the output is correct self.assertEqual(len(out), 12) @@ -311,7 +312,8 @@ class Test_TextTestRunner(unittest.TestCase): # in all these cases no warnings are printed for args in args_list: p = subprocess.Popen(args, **opts) - out, err = get_parse_out_err(p) + with p: + out, err = get_parse_out_err(p) self.assertIn(b'OK', err) self.assertEqual(len(out), 0) @@ -320,7 +322,8 @@ class Test_TextTestRunner(unittest.TestCase): # unittest warnings only once p = subprocess.Popen([sys.executable, '_test_warnings.py', 'always'], **opts) - out, err = get_parse_out_err(p) + with p: + out, err = get_parse_out_err(p) self.assertIn(b'OK', err) self.assertEqual(len(out), 14) for msg in [b'dw', b'iw', b'uw', b'rw']: