summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_faulthandler.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-06-29 11:44:05 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-06-29 11:44:05 (GMT)
commit7e32f3a401e7cc420a0db559c0ad4f0349e64d33 (patch)
tree8b3edf4ac31d82ed1cb0e384f183def8638ec942 /Lib/test/test_faulthandler.py
parent0b8f0c276699c045ff55510186025783219bec61 (diff)
downloadcpython-7e32f3a401e7cc420a0db559c0ad4f0349e64d33.zip
cpython-7e32f3a401e7cc420a0db559c0ad4f0349e64d33.tar.gz
cpython-7e32f3a401e7cc420a0db559c0ad4f0349e64d33.tar.bz2
Issue #12400: fix test_faulthandler if regrtest captures sys.stderr
faulthandler.enable() requires that sys.stderr has a fileno() method.
Diffstat (limited to 'Lib/test/test_faulthandler.py')
-rw-r--r--Lib/test/test_faulthandler.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
index 0ddfc7f..291fac5 100644
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -1,6 +1,7 @@
from contextlib import contextmanager
import datetime
import faulthandler
+import os
import re
import signal
import subprocess
@@ -230,17 +231,30 @@ faulthandler._read_null()
self.assertNotEqual(exitcode, 0)
def test_is_enabled(self):
- was_enabled = faulthandler.is_enabled()
+ null_stderr = None
+ orig_stderr = sys.stderr
try:
- faulthandler.enable()
- self.assertTrue(faulthandler.is_enabled())
- faulthandler.disable()
- self.assertFalse(faulthandler.is_enabled())
- finally:
- if was_enabled:
+ # regrtest may replace sys.stderr by io.StringIO object, but
+ # faulthandler.enable() requires that sys.stderr has a fileno()
+ # method
+ null_stderr = open(os.devnull, 'w')
+ sys.stderr = null_stderr
+
+ was_enabled = faulthandler.is_enabled()
+ try:
faulthandler.enable()
- else:
+ self.assertTrue(faulthandler.is_enabled())
faulthandler.disable()
+ self.assertFalse(faulthandler.is_enabled())
+ finally:
+ if was_enabled:
+ faulthandler.enable()
+ else:
+ faulthandler.disable()
+ finally:
+ sys.stderr = orig_stderr
+ if null_stderr is not None:
+ null_stderr.close()
def check_dump_traceback(self, filename):
"""