From d0ec4fe34560ba0a183b06ef441ca60d8e4a981e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 26 Jun 2024 15:38:41 +0500 Subject: [PATCH] core tests - print unprocessed calls in pytest verbose mode e.g. if you start test with pytest test_style.py -vv it will be easier to guess why it couldn't find a call ``` E Exception: was not called with run: E - {'type': 'SHOULD_BE_CALLED', 'number': None, 'call': {'name': 'run', 'args': ('style.add_surface_style',), 'kwargs': {'style': 'style', 'ifc_class': 'IfcSurfaceStyleShading', 'attributes': 'attributes'}}} E Unprocessed calls: E - {'name': 'run', 'args': ('style.add_style',), 'kwargs': {'name': 'name'}} E - {'name': 'link', 'args': ('element', 'obj'), 'kwargs': {}} E - {'name': 'run', 'args': ('style.add_surface_style',), 'kwargs': {'style': 'element', 'ifc_class': 'IfcSurfaceStyleShading', 'attributes': 'attributes'}} ``` --- src/blenderbim/test/core/bootstrap.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/test/core/bootstrap.py b/src/blenderbim/test/core/bootstrap.py index 6ec9c206ce..0ce584280a 100644 --- a/src/blenderbim/test/core/bootstrap.py +++ b/src/blenderbim/test/core/bootstrap.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with BlenderBIM Add-on. If not, see . +import sys import json import pytest import blenderbim.core.tool @@ -293,4 +294,15 @@ class Prophecy: raise Exception(f"Called {count}: {prediction}") else: if prediction["call"] not in self.calls: - raise Exception(f"{self.subject} was not called with {prediction['call']['name']}: {prediction}") + error_msg = f"{self.subject} was not called with {prediction['call']['name']}:\n - {prediction}" + + # Print all unprocessed calls if pytest was started in verbose mode. + if "-v" in sys.argv or "-vv" in sys.argv: + if not self.calls: + error_msg += "\nNo unprocessed calls." + else: + error_msg += "\nUnprocessed calls:" + for call in self.calls: + error_msg += f"\n - {call}" + + raise Exception(error_msg)