bpo-31479: Always reset the signal alarm in tests (#3588)

* 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
This commit is contained in:
Victor Stinner 2017-09-19 09:36:54 -07:00 committed by GitHub
parent a92941ff12
commit 9abee722d4
6 changed files with 56 additions and 40 deletions

View file

@ -3940,6 +3940,7 @@ class SignalsTest(unittest.TestCase):
if isinstance(exc, RuntimeError):
self.assertTrue(str(exc).startswith("reentrant call"), str(exc))
finally:
signal.alarm(0)
wio.close()
os.close(r)
@ -3968,6 +3969,7 @@ class SignalsTest(unittest.TestCase):
# - third raw read() returns b"bar"
self.assertEqual(decode(rio.read(6)), "foobar")
finally:
signal.alarm(0)
rio.close()
os.close(w)
os.close(r)
@ -4035,6 +4037,7 @@ class SignalsTest(unittest.TestCase):
self.assertIsNone(error)
self.assertEqual(N, sum(len(x) for x in read_results))
finally:
signal.alarm(0)
write_finished = True
os.close(w)
os.close(r)