summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pty.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-06-01 13:23:10 (GMT)
committerGitHub <noreply@github.com>2018-06-01 13:23:10 (GMT)
commit95681c7a7ddd436ba7d6c10d1202c33dd6bd648b (patch)
tree09d65225dac18d9be9dc0eb71cc8fca13c68f361 /Lib/test/test_pty.py
parent8f7bd307ce54570275700523532c1e098ce67b60 (diff)
downloadcpython-95681c7a7ddd436ba7d6c10d1202c33dd6bd648b.zip
cpython-95681c7a7ddd436ba7d6c10d1202c33dd6bd648b.tar.gz
cpython-95681c7a7ddd436ba7d6c10d1202c33dd6bd648b.tar.bz2
bpo-31479: Always reset the signal alarm in tests (GH-3588) (GH-7312)
* bpo-31479: Always reset the signal alarm in tests Use "try: ... finally: signal.signal(0)" pattern to make sure that tests don't "leak" a pending fatal signal alarm. * Move two more alarm() calls into the try block Fix also typo: replace signal.signal(0) with signal.alarm(0) * Move another signal.alarm() into the try block (cherry picked from commit 9abee722d448c1c00c7d4e11ce242ec7b13e5c49)
Diffstat (limited to 'Lib/test/test_pty.py')
-rw-r--r--Lib/test/test_pty.py9
1 files changed, 3 insertions, 6 deletions
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py
index 45ebea5..cd934bf 100644
--- a/Lib/test/test_pty.py
+++ b/Lib/test/test_pty.py
@@ -69,14 +69,11 @@ class PtyTest(unittest.TestCase):
def setUp(self):
# isatty() and close() can hang on some platforms. Set an alarm
# before running the test to make sure we don't hang forever.
- self.old_alarm = signal.signal(signal.SIGALRM, self.handle_sig)
+ old_alarm = signal.signal(signal.SIGALRM, self.handle_sig)
+ self.addCleanup(signal.signal, signal.SIGALRM, old_alarm)
+ self.addCleanup(signal.alarm, 0)
signal.alarm(10)
- def tearDown(self):
- # remove alarm, restore old alarm handler
- signal.alarm(0)
- signal.signal(signal.SIGALRM, self.old_alarm)
-
def handle_sig(self, sig, frame):
self.fail("isatty hung")