Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9db2ae7

Browse files
committed
Fix ResourceWarning in test_unittest when interrupted
1 parent 06ddd35 commit 9db2ae7

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Lib/unittest/test/test_runner.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ def get_parse_out_err(p):
290290

291291
# no args -> all the warnings are printed, unittest warnings only once
292292
p = subprocess.Popen([sys.executable, '_test_warnings.py'], **opts)
293-
out, err = get_parse_out_err(p)
293+
with p:
294+
out, err = get_parse_out_err(p)
294295
self.assertIn(b'OK', err)
295296
# check that the total number of warnings in the output is correct
296297
self.assertEqual(len(out), 12)
@@ -311,7 +312,8 @@ def get_parse_out_err(p):
311312
# in all these cases no warnings are printed
312313
for args in args_list:
313314
p = subprocess.Popen(args, **opts)
314-
out, err = get_parse_out_err(p)
315+
with p:
316+
out, err = get_parse_out_err(p)
315317
self.assertIn(b'OK', err)
316318
self.assertEqual(len(out), 0)
317319

@@ -320,7 +322,8 @@ def get_parse_out_err(p):
320322
# unittest warnings only once
321323
p = subprocess.Popen([sys.executable, '_test_warnings.py', 'always'],
322324
**opts)
323-
out, err = get_parse_out_err(p)
325+
with p:
326+
out, err = get_parse_out_err(p)
324327
self.assertIn(b'OK', err)
325328
self.assertEqual(len(out), 14)
326329
for msg in [b'dw', b'iw', b'uw', b'rw']:

0 commit comments

Comments
 (0)