From f01f3d473fc79868e2d09978a3258f49625faa00 Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Sun, 30 May 2021 22:24:24 -0700 Subject: [PATCH] Have debug.printExc emits RuntimeWarning Several bugs have snuck through due to being wrapped with printExc, which would prevent the exception from raising, but printing the trace to the console. In pytest, this output is not captured at all, and is invisible unless the -s parameter is added. This PR changes the print statement to a runtime warning, which pytest will capture. --- pyqtgraph/debug.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pyqtgraph/debug.py b/pyqtgraph/debug.py index 37b612cd..5b5dcb49 100644 --- a/pyqtgraph/debug.py +++ b/pyqtgraph/debug.py @@ -113,11 +113,10 @@ def getExc(indent=4, prefix='| ', skip=1): def printExc(msg='', indent=4, prefix='|'): """Print an error message followed by an indented exception backtrace (This function is intended to be called within except: blocks)""" - exc = getExc(indent, prefix + ' ', skip=2) - print("[%s] %s\n" % (time.strftime("%H:%M:%S"), msg)) - print(" "*indent + prefix + '='*30 + '>>') - print(exc) - print(" "*indent + prefix + '='*30 + '<<') + exc = getExc(indent=0, prefix="", skip=2) + # print(" "*indent + prefix + '='*30 + '>>') + warnings.warn("\n".join([msg, exc]), RuntimeWarning, stacklevel=2) + # print(" "*indent + prefix + '='*30 + '<<') def printTrace(msg='', indent=4, prefix='|'):