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: <class 'abc.Ifc'> 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'}}
```
This commit is contained in:
Andrej730
2024-06-26 15:38:41 +05:00
parent 665bf00f8b
commit d0ec4fe345
+13 -1
View File
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
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)