From 0ab9fecea45b479a147331a7120bddcb12ed29b8 Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Mon, 24 Aug 2020 19:16:03 +0100 Subject: [PATCH] suppress_thread_exceptions doesn't fail under Python 3.6. It uses threading.excepthook, which doesn't exist in pre-3.8 Python. But there's no need to break all the tests under 3.6. suppress_thread_exceptions was introduced in commit 001698cd. --- kepi/sombrero_sendpub/tests/__init__.py | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/kepi/sombrero_sendpub/tests/__init__.py b/kepi/sombrero_sendpub/tests/__init__.py index 677aa1a..a9cc7c2 100644 --- a/kepi/sombrero_sendpub/tests/__init__.py +++ b/kepi/sombrero_sendpub/tests/__init__.py @@ -7,9 +7,25 @@ def suppress_thread_exceptions(): Context manager which causes exceptions in threads not to be printed. See https://stackoverflow.com/questions/63206653/ . """ - orig = threading.excepthook - threading.excepthook = lambda a: None try: - yield - finally: - threading.excepthook = orig + orig = threading.excepthook + threading.excepthook = lambda a: None + try: + yield + finally: + threading.excepthook = orig + except AttributeError: + + # Python 3.6 doesn't have threading.excepthook, + # but everything else in kepi works. So if it's + # missing, we work around that. + + print("""Warning: + You are running a version of Python without threading.excepthook. + You will see spurious error messages during testing. + """) + + try: + yield + finally: + pass