summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2010-12-04 09:59:52 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2010-12-04 09:59:52 (GMT)
commitb4162305bba375c5f18bd69d1b90b45fc35ca8f1 (patch)
tree90469aeec113833514a3b12ba732b084fde0dc61 /Lib/test
parent10064e9d7a89b178b5a008fdc83813c3c7820c6b (diff)
downloadcpython-b4162305bba375c5f18bd69d1b90b45fc35ca8f1.zip
cpython-b4162305bba375c5f18bd69d1b90b45fc35ca8f1.tar.gz
cpython-b4162305bba375c5f18bd69d1b90b45fc35ca8f1.tar.bz2
refactor the warning test.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_subprocess.py34
1 files changed, 11 insertions, 23 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 8759941..f07f490 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -59,31 +59,19 @@ class BaseTestCase(unittest.TestCase):
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])
+ with warnings.catch_warnings(record=True) as warnlist:
+ warnings.simplefilter("always")
+ subprocess.call(quick_process, close_fds=True)
+ self.assertEqual([], warnlist)
+ subprocess.call(quick_process, close_fds=False)
+ self.assertEqual([], warnlist)
+ with self.assertWarns(DeprecationWarning) as wm:
+ subprocess.Popen(quick_process).wait()
+ self.assertEqual(1, len(wm.warnings))
+ self.assertIn('close_fds parameter was not specified',
+ str(wm.warnings[0]))
class ProcessTestCase(BaseTestCase):