From 0d909b450bf800bea83f03192d747dacb307df85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 24 May 2023 14:09:53 +0200 Subject: [PATCH] tests: Provide a meaningful error message When the sigint subprocess raises a Python exception (e.g. due to missing features), the process remains open indefinitely, which causes the unit test to time out and the Python interpreter to terminate while the subprocess pipe is still open. --- testsuite/python/sigint.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/testsuite/python/sigint.py b/testsuite/python/sigint.py index 738d8e9a2f..933fcd0ec9 100644 --- a/testsuite/python/sigint.py +++ b/testsuite/python/sigint.py @@ -25,6 +25,12 @@ import os +EXPECTED_TRACEBACK_ENDING = """ in handle_sigint + signal.raise_signal(signal.Signals.SIGINT) +KeyboardInterrupt +""" + + class SigintTest(ut.TestCase): script = str(pathlib.Path(__file__).parent / 'sigint_child.py') @@ -43,8 +49,8 @@ def check_signal_handling(self, process, sig): self.assertEqual(traceback, "") elif sig == signal.Signals.SIGINT: self.assertIn(" self.integrator.run(", traceback) - self.assertTrue(traceback.endswith( - " in handle_sigint\n signal.raise_signal(signal.Signals.SIGINT)\nKeyboardInterrupt\n")) + self.assertTrue(traceback.endswith(EXPECTED_TRACEBACK_ENDING), + msg=f"Traceback failed string match:\n{traceback}") def test_signal_handling(self): signals = [signal.Signals.SIGINT, signal.Signals.SIGTERM]