mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
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:
@@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# 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/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
import pytest
|
import pytest
|
||||||
import blenderbim.core.tool
|
import blenderbim.core.tool
|
||||||
@@ -293,4 +294,15 @@ class Prophecy:
|
|||||||
raise Exception(f"Called {count}: {prediction}")
|
raise Exception(f"Called {count}: {prediction}")
|
||||||
else:
|
else:
|
||||||
if prediction["call"] not in self.calls:
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user