Skip to content

Bug fix: Open3D mock leak between test_yolo.py and test_lidar.py causes 2 test failures#572

Open
Vo1denz wants to merge 2 commits into
JdeRobot:masterfrom
Vo1denz:issue_571_fix_open3d_isinstance
Open

Bug fix: Open3D mock leak between test_yolo.py and test_lidar.py causes 2 test failures#572
Vo1denz wants to merge 2 commits into
JdeRobot:masterfrom
Vo1denz:issue_571_fix_open3d_isinstance

Conversation

@Vo1denz
Copy link
Copy Markdown

@Vo1denz Vo1denz commented Apr 29, 2026

Closes #571

Problem

Two tests failed when running the full suite:

  • test_build_point_cloud
  • test_view_point_cloud

Root cause

test_yolo.py stubs open3d with MagicMock at module level (during pytest
collection) to avoid importing the heavy C-extension. The stub persists
in sys.modules, so when perceptionmetrics.utils.lidar imports open3d it
gets the MagicMock. build_point_cloud then returns a MagicMock object
instead of a real PointCloud.

Fix

Three changes:

  1. tests/conftest.py — pre-imports real open3d before any test module
    is collected. The if _stub not in sys.modules guard in test_yolo.py
    then skips stubbing it.
  2. tests/test_lidar.py — replaced isinstance(obj, o3d.geometry.PointCloud)
    with type(obj).name == "PointCloud" as a secondary fix for
    Open3D 0.19.0 pybind11 compatibility.
  3. tests/test_yolo.py — minor cleanup for clarity.

Testing

Full suite: 46 passed, 0 failed (previously 44 passed, 2 failed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: isinstance check fails with Open3D 0.19.0 in test_lidar.py

1 participant