14
0
forked from pool/python-loguru

Accepting request 873587 from home:jayvdb:branches:devel:languages:python

- Add pytest-6.2-excepthooks.patch for compatibility with pytest 6.2

OBS-URL: https://build.opensuse.org/request/show/873587
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-loguru?expand=0&rev=10
This commit is contained in:
John Vandenberg
2021-02-19 01:58:26 +00:00
committed by Git OBS Bridge
parent 6c947d8afb
commit 167d279f3c
3 changed files with 94 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
From 31cf758ee9d22dbfa125f38153782fe20ac9dce5 Mon Sep 17 00:00:00 2001
From: Delgan <delgan.py@gmail.com>
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()

View File

@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Fri Feb 19 01:51:00 UTC 2021 - John Vandenberg <jayvdb@gmail.com>
- Add pytest-6.2-excepthooks.patch for compatibility with pytest 6.2
-------------------------------------------------------------------
Mon Feb 8 22:31:43 UTC 2021 - John Vandenberg <jayvdb@gmail.com>

View File

@@ -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