diff --git a/debian/patches/fix-test-due-to-excepthook.patch b/debian/patches/fix-test-due-to-excepthook.patch new file mode 100644 index 0000000..97a9f8a --- /dev/null +++ b/debian/patches/fix-test-due-to-excepthook.patch @@ -0,0 +1,87 @@ +From 31cf758ee9d22dbfa125f38153782fe20ac9dce5 Mon Sep 17 00:00:00 2001 +From: Delgan +Date: Sat, 19 Dec 2020 16:29:07 +0100 +Subject: [PATCH] Fix failing tests due to new "excepthook" in threads + +--- + tests/test_add_option_enqueue.py | 44 +++++++++++++++++++++++++------- + 1 file changed, 35 insertions(+), 9 deletions(-) + +diff --git a/tests/test_add_option_enqueue.py b/tests/test_add_option_enqueue.py +index 50e1843..4b7c891 100644 +--- a/tests/test_add_option_enqueue.py ++++ b/tests/test_add_option_enqueue.py +@@ -4,6 +4,9 @@ + import re + import sys + import pickle ++import contextlib ++import threading ++import traceback + + + class NotPicklable: +@@ -29,6 +32,27 @@ def write(self, message): + print(message, end="") + + ++@contextlib.contextmanager ++def default_threading_excepthook(): ++ if not hasattr(threading, "excepthook"): ++ yield ++ return ++ ++ # Pytest added "PytestUnhandledThreadExceptionWarning", we need to ++ # remove it temporarily for somes tests checking exceptions in threads. ++ ++ def excepthook(args): ++ print("Exception in thread:", file=sys.stderr, flush=True) ++ traceback.print_exception( ++ args.exc_type, args.exc_value, args.exc_traceback, file=sys.stderr ++ ) ++ ++ old_excepthook = threading.excepthook ++ threading.excepthook = excepthook ++ yield ++ threading.excepthook = old_excepthook ++ ++ + def test_enqueue(): + x = [] + +@@ -139,10 +163,11 @@ def test_not_caught_exception_queue_put(writer, capsys): + def test_not_caught_exception_queue_get(writer, capsys): + logger.add(writer, enqueue=True, catch=False, format="{message}") + +- logger.info("It's fine") +- logger.bind(broken=NotUnpicklable()).info("Bye bye...") +- logger.info("It's not fine") +- logger.remove() ++ with default_threading_excepthook(): ++ logger.info("It's fine") ++ logger.bind(broken=NotUnpicklable()).info("Bye bye...") ++ logger.info("It's not fine") ++ logger.remove() + + out, err = capsys.readouterr() + lines = err.strip().splitlines() +@@ -152,13 +177,14 @@ def test_not_caught_exception_queue_get(writer, capsys): + assert lines[-1].endswith("UnpicklingError: You shall not de-serialize me!") + + +-def test_not_caught_exception_sink_write(capsys): ++def test_not_caught_exception_sink_write(monkeypatch, capsys): + logger.add(NotWritable(), enqueue=True, catch=False, format="{message}") + +- logger.info("It's fine") +- logger.bind(fail=True).info("Bye bye...") +- logger.info("It's not fine") +- logger.remove() ++ with default_threading_excepthook(): ++ logger.info("It's fine") ++ logger.bind(fail=True).info("Bye bye...") ++ logger.info("It's not fine") ++ logger.remove() + + out, err = capsys.readouterr() + lines = err.strip().splitlines() diff --git a/debian/patches/series b/debian/patches/series index f7ccb38..213dc0e 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1 +1,2 @@ test_time_rotation_reopening_native.patch +fix-test-due-to-excepthook.patch