diff --git a/pytest-6.2-excepthooks.patch b/pytest-6.2-excepthooks.patch new file mode 100644 index 0000000..2bcf8c7 --- /dev/null +++ b/pytest-6.2-excepthooks.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/python-loguru.changes b/python-loguru.changes index da3177d..a0e28e9 100644 --- a/python-loguru.changes +++ b/python-loguru.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Fri Feb 19 01:51:00 UTC 2021 - John Vandenberg + +- Add pytest-6.2-excepthooks.patch for compatibility with pytest 6.2 + ------------------------------------------------------------------- Mon Feb 8 22:31:43 UTC 2021 - John Vandenberg diff --git a/python-loguru.spec b/python-loguru.spec index fbbfec0..9d8dc1b 100644 --- a/python-loguru.spec +++ b/python-loguru.spec @@ -26,6 +26,7 @@ License: MIT Group: Development/Languages/Python URL: https://github.com/Delgan/loguru Source: https://files.pythonhosted.org/packages/source/l/loguru/loguru-%{version}.tar.gz +Patch0: https://github.com/Delgan/loguru/commit/31cf758ee9d22dbfa125f38153782fe20ac9dce5.patch#/pytest-6.2-excepthooks.patch BuildRequires: %{python_module colorama} BuildRequires: %{python_module pytest} BuildRequires: %{python_module setuptools} @@ -46,6 +47,7 @@ which dispatches log messages to configured handlers. %prep %setup -q -n loguru-%{version} +%patch0 -p1 %build %python_build