mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 03:28:33 +00:00
Centralise model test fixtures via conftest
bim/module/model/conftest.py exposes the autouse _require_real_bpy skip-guard, four make_* factories (obj / element / context / ifc_file), and a patched_tool context-manager factory that wires the half-dozen tool.* boundary patches every gizmo + decorator test was repeating. Existing test files in the directory drop their local copies of _require_real_bpy and adopt the patched_tool / make_* fixtures where the call site simplifies — test_mep_port_operators.py is the biggest beneficiary (−89 LOC). No production behaviour change. Generated with the assistance of an AI coding tool.
This commit is contained in:
@@ -54,15 +54,31 @@ module if the helper count grows past ~6 or any helper picks up its own
|
||||
non-trivial dependencies."""
|
||||
|
||||
import contextlib
|
||||
import types
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import pytest
|
||||
|
||||
from bonsai import tool
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _require_real_bpy():
|
||||
"""Skip every test in this directory when ``bpy`` is mocked or absent.
|
||||
|
||||
The model gizmo / decorator suite reaches into Blender's RNA layer
|
||||
(``bpy.types.Operator``, registered ``bl_idname`` lookups, ``Modifier``
|
||||
predicates) that ``Mock`` cannot impersonate, so a tool-lane run with a
|
||||
stubbed ``bpy`` would error rather than meaningfully exercise the
|
||||
contract. The autouse scope means new test files added under this
|
||||
directory inherit the gate without re-declaring it."""
|
||||
if not isinstance(bpy, types.ModuleType) or hasattr(bpy, "_mock_name"):
|
||||
pytest.skip("requires real Blender (bpy is mocked or absent)")
|
||||
|
||||
|
||||
def make_obj(*, session_uid=None, selected=True, **attrs):
|
||||
"""Mock a ``bpy.types.Object`` with attributes commonly read by gizmos.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user