From 7d77ea032c87bb5ecad95f92fab82223a4a3108b Mon Sep 17 00:00:00 2001 From: Gorgious56 Date: Wed, 27 May 2026 13:26:38 +0200 Subject: [PATCH] Add addon-load smoke test pinning register/unregister cycle Surfaces any regression in: * the modules dict in bim/__init__.py (added a folder, forgot the entry) * PointerProperty wiring on bpy.types.{Scene,Object,...} * registry-driven GizmoPreferences auto-registration in tool.Parametric.iter_gizmo_preference_classes * bpy.app.handlers append/remove balance * every register()/unregister() across the 45+ feature modules as a single PASSED/FAILED test instead of the silent "addon failed to enable" users encounter in a fresh Blender. Paired with the existing test_parametric_registry.py contract tests, this catches both the registry-shape regressions (operators/PropertyGroups/predicates) and the registration-mechanics regressions (PointerProperty types not registered before their owners). Generated with the assistance of an AI coding tool. --- src/bonsai/test/bim/test_addon_lifecycle.py | 60 +++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/bonsai/test/bim/test_addon_lifecycle.py diff --git a/src/bonsai/test/bim/test_addon_lifecycle.py b/src/bonsai/test/bim/test_addon_lifecycle.py new file mode 100644 index 0000000000..16ea0b9f0c --- /dev/null +++ b/src/bonsai/test/bim/test_addon_lifecycle.py @@ -0,0 +1,60 @@ +# Bonsai - OpenBIM Blender Add-on +# Copyright (C) 2026 +# +# This file is part of Bonsai. +# +# Bonsai is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Bonsai is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Bonsai. If not, see . +# +# This file was generated with the assistance of an AI coding tool. + +"""Addon-load smoke for ``bonsai``. + +Pins the registration/unregistration cycle as a runnable contract. The cycle +exercises every ``register()`` site across ``bim/__init__.py``'s modules dict, +every ``PointerProperty`` attachment, every gizmo-prefs auto-registration, and +every ``bpy.app.handlers`` install. A regression in any of those surfaces here +as an exception with a traceback that points at the failing site, instead of +the silent ``addon failed to enable`` users see in a fresh Blender.""" + +import types + +import bpy +import pytest + +pytestmark = pytest.mark.model + + +@pytest.fixture(autouse=True) +def _require_real_bpy(): + if not isinstance(bpy, types.ModuleType) or hasattr(bpy, "_mock_name"): + pytest.skip("requires real Blender (bpy is mocked or absent)") + + +def test_addon_unregister_then_register_does_not_raise(): + """Running the suite has already enabled the addon. Cycle through one + unregister + register to exercise both halves, then leave the addon + enabled so downstream tests in the same Blender session keep working.""" + import bonsai + + bonsai.unregister() + try: + bonsai.register() + except Exception: + # Re-raise after attempting to leave the session in a usable state for + # any tests that run after this one. + try: + bonsai.register() + except Exception: + pass + raise