summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-07-31 15:49:43 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-07-31 15:49:43 (GMT)
commit6fb1e740c67d8940fe27883d77f0dc46431aa9b4 (patch)
tree9f165889ccdc7add17c4301b23c969e48fa740fc /Lib/test/test_asyncio
parent062759f1dcfc025d1aae430ad89e22b8fd02dbf2 (diff)
downloadcpython-6fb1e740c67d8940fe27883d77f0dc46431aa9b4.zip
cpython-6fb1e740c67d8940fe27883d77f0dc46431aa9b4.tar.gz
cpython-6fb1e740c67d8940fe27883d77f0dc46431aa9b4.tar.bz2
Fix ResourceWarning in asyncio.BaseSubprocessTransport
Issue #24763: Fix resource warnings when asyncio.BaseSubprocessTransport constructor fails, if subprocess.Popen raises an exception for example. Patch written by Martin Richard, test written by me.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index ea85e19..d138c26 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -1,6 +1,7 @@
import signal
import sys
import unittest
+import warnings
from unittest import mock
import asyncio
@@ -413,6 +414,20 @@ class SubprocessMixin:
# the transport was not notified yet
self.assertFalse(killed)
+ def test_popen_error(self):
+ # Issue #24763: check that the subprocess transport is closed
+ # when BaseSubprocessTransport fails
+ with mock.patch('subprocess.Popen') as popen:
+ exc = ZeroDivisionError
+ popen.side_effect = exc
+
+ create = asyncio.create_subprocess_exec(sys.executable, '-c',
+ 'pass', loop=self.loop)
+ with warnings.catch_warnings(record=True) as warns:
+ with self.assertRaises(exc):
+ self.loop.run_until_complete(create)
+ self.assertEqual(warns, [])
+
if sys.platform != 'win32':
# Unix