summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-08-01 18:16:15 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2006-08-01 18:16:15 (GMT)
commit86e1e38059c7f2a1d8bdc4123a1600bc7b7a0f79 (patch)
tree9fe64ea43c721ccb0a5dbde7f410e2c2f142a589
parent11d68a6ac4aff428a1b680344962bfb444069453 (diff)
downloadcpython-86e1e38059c7f2a1d8bdc4123a1600bc7b7a0f79.zip
cpython-86e1e38059c7f2a1d8bdc4123a1600bc7b7a0f79.tar.gz
cpython-86e1e38059c7f2a1d8bdc4123a1600bc7b7a0f79.tar.bz2
[Patch #1520905] Attempt to suppress core file created by test_subprocess.py.
Patch by Douglas Greiman. The test_run_abort() testcase produces a core file on Unix systems, even though the test is successful. This can be confusing or alarming to someone who runs 'make test' and then finds that the Python interpreter apparently crashed.
-rw-r--r--Lib/test/test_subprocess.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index f2c3083..1e18eca 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -476,10 +476,36 @@ class ProcessTestCase(unittest.TestCase):
else:
self.fail("Expected OSError")
+ def _suppress_core_files(self):
+ """Try to prevent core files from being created.
+ Returns previous ulimit if successful, else None.
+ """
+ try:
+ import resource
+ old_limit = resource.getrlimit(resource.RLIMIT_CORE)
+ resource.setrlimit(resource.RLIMIT_CORE, (0,0))
+ return old_limit
+ except (ImportError, ValueError, resource.error):
+ return None
+
+ def _unsuppress_core_files(self, old_limit):
+ """Return core file behavior to default."""
+ if old_limit is None:
+ return
+ try:
+ import resource
+ resource.setrlimit(resource.RLIMIT_CORE, old_limit)
+ except (ImportError, ValueError, resource.error):
+ return
+
def test_run_abort(self):
# returncode handles signal termination
- p = subprocess.Popen([sys.executable,
- "-c", "import os; os.abort()"])
+ old_limit = self._suppress_core_files()
+ try:
+ p = subprocess.Popen([sys.executable,
+ "-c", "import os; os.abort()"])
+ finally:
+ self._unsuppress_core_files(old_limit)
p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT)