summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2010-12-04 09:10:44 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2010-12-04 09:10:44 (GMT)
commitd23047b62c6f885def9020bd9b304110f9b9c52d (patch)
tree4adeb352a619ce0ce869f93ea792d6ab8403ee64 /Lib/test/test_subprocess.py
parent35f08f0f844186f3a3f3a4dd477ea22d589886de (diff)
downloadcpython-d23047b62c6f885def9020bd9b304110f9b9c52d.zip
cpython-d23047b62c6f885def9020bd9b304110f9b9c52d.tar.gz
cpython-d23047b62c6f885def9020bd9b304110f9b9c52d.tar.bz2
issue7213 + issue2320: Cause a DeprecationWarning if the close_fds argument is
not passed to subprocess.Popen as the default value will be changing in a future Python to the safer and more often desired value of True. DeprecationWarnings that show up in a lot of existing code are controversial and have caused pain in the past. I'd like to leave this on for 3.2 beta1 and see how things go. We can remove the warning if it is deemed too noisy during any betas. (case study: the md5 and sha module DeprecationWarnings are loathed around the world as those modules were never going to be removed in 2.x and 2to3 has a fixer for code that uses them)
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index ec1e186..8759941 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -9,6 +9,7 @@ import tempfile
import time
import re
import sysconfig
+import warnings
try:
import gc
except ImportError:
@@ -57,6 +58,34 @@ class BaseTestCase(unittest.TestCase):
self.assertEqual(actual, expected, msg)
+class DeprecationWarningTests(BaseTestCase):
+ def setUp(self):
+ BaseTestCase.setUp(self)
+ self._saved_warn = warnings.warn
+ self._warn_calls = []
+ warnings.warn = self._record_warn
+
+ def tearDown(self):
+ warnings.warn = self._saved_warn
+ BaseTestCase.tearDown(self)
+
+ def _record_warn(self, *args):
+ """A warnings.warn function that records calls."""
+ self._warn_calls.append(args)
+ self._saved_warn(*args)
+
+ def testCloseFdsWarning(self):
+ quick_process = [sys.executable, "-c", "import sys; sys.exit(0)"]
+ subprocess.call(quick_process, close_fds=True)
+ self.assertEqual([], self._warn_calls)
+ subprocess.call(quick_process, close_fds=False)
+ self.assertEqual([], self._warn_calls)
+ self.assertWarns(DeprecationWarning, subprocess.call, quick_process)
+ self.assertEqual(1, len(self._warn_calls))
+ self.assertIn('close_fds parameter was not specified',
+ self._warn_calls[0][0])
+
+
class ProcessTestCase(BaseTestCase):
def test_call_seq(self):
@@ -1233,7 +1262,8 @@ def test_main():
ProcessTestCaseNoPoll,
HelperFunctionTests,
CommandsWithSpaces,
- ContextManagerTests)
+ ContextManagerTests,
+ DeprecationWarningTests)
support.run_unittest(*unit_tests)
support.reap_children()