mirror of
https://github.com/python/cpython.git
synced 2025-08-29 13:15:11 +00:00
asyncio: Close transports in tests
* Use test_utils.run_briefly() to execute pending calls to really close transports * sslproto: mock also _SSLPipe.shutdown(), it's need to close the transport * pipe test: the test doesn't close explicitly the PipeHandle, so ignore the warning instead * test_popen: use the context manager ("with p:") to explicitly close pipes
This commit is contained in:
parent
4bf22e033e
commit
ab8848bc2a
4 changed files with 15 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
|||
import socket
|
||||
import sys
|
||||
import unittest
|
||||
import warnings
|
||||
from unittest import mock
|
||||
|
||||
if sys.platform != 'win32':
|
||||
|
@ -115,8 +116,10 @@ class PipeTests(unittest.TestCase):
|
|||
self.assertEqual(p.handle, h)
|
||||
|
||||
# check garbage collection of p closes handle
|
||||
del p
|
||||
support.gc_collect()
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings("ignore", "", ResourceWarning)
|
||||
del p
|
||||
support.gc_collect()
|
||||
try:
|
||||
_winapi.CloseHandle(h)
|
||||
except OSError as e:
|
||||
|
@ -170,7 +173,9 @@ class PopenTests(unittest.TestCase):
|
|||
self.assertTrue(msg.upper().rstrip().startswith(out))
|
||||
self.assertTrue(b"stderr".startswith(err))
|
||||
|
||||
p.wait()
|
||||
# The context manager calls wait() and closes resources
|
||||
with p:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue