summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index c9a3e1b..71ae0db 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -292,7 +292,7 @@ class ProcessTestCase(unittest.TestCase):
self.assertEqual(stdout, None)
# When running with a pydebug build, the # of references is outputted
# to stderr, so just check if stderr at least started with "pinapple"
- self.assert_(stderr.startswith(b"pineapple"))
+ self.assertEqual(remove_stderr_debug_decorations(stderr), b"pineapple")
def test_communicate(self):
p = subprocess.Popen([sys.executable, "-c",
@@ -307,6 +307,22 @@ class ProcessTestCase(unittest.TestCase):
self.assertEqual(remove_stderr_debug_decorations(stderr),
b"pineapple")
+ # This test is Linux specific for simplicity to at least have
+ # some coverage. It is not a platform specific bug.
+ if os.path.isdir('/proc/%d/fd' % os.getpid()):
+ # Test for the fd leak reported in http://bugs.python.org/issue2791.
+ def test_communicate_pipe_fd_leak(self):
+ fd_directory = '/proc/%d/fd' % os.getpid()
+ num_fds_before_popen = len(os.listdir(fd_directory))
+ p = subprocess.Popen([sys.executable, '-c', 'print()'],
+ stdout=subprocess.PIPE)
+ p.communicate()
+ num_fds_after_communicate = len(os.listdir(fd_directory))
+ del p
+ num_fds_after_destruction = len(os.listdir(fd_directory))
+ self.assertEqual(num_fds_before_popen, num_fds_after_destruction)
+ self.assertEqual(num_fds_before_popen, num_fds_after_communicate)
+
def test_communicate_returns(self):
# communicate() should return None if no redirection is active
p = subprocess.Popen([sys.executable, "-c",