diff --git a/perceptionmetrics/utils/detection_metrics.py b/perceptionmetrics/utils/detection_metrics.py index f76505dc..6da89f18 100644 --- a/perceptionmetrics/utils/detection_metrics.py +++ b/perceptionmetrics/utils/detection_metrics.py @@ -297,7 +297,7 @@ def get_overall_precision_recall_curve(self) -> Dict[str, List[float]]: return {"precision": [0.0], "recall": [0.0]} fn_count = sum(1 for d in all_detections if d[1] == -1) - + # Sort by score all_detections = sorted( [d for d in all_detections if d[0] is not None], key=lambda x: -x[0] diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..a05c4a1b --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,5 @@ +# tests/conftest.py +# Pre-import open3d before any test module is collected. +# test_yolo.py stubs open3d only if it's NOT already in sys.modules. +# Loading it here first ensures test_lidar.py gets the real open3d. +import open3d # noqa: F401 diff --git a/tests/test_lidar.py b/tests/test_lidar.py index c94f57a6..a8fd31b3 100644 --- a/tests/test_lidar.py +++ b/tests/test_lidar.py @@ -206,7 +206,7 @@ def test_build_point_cloud(self, sample_points, sample_colors): """Test build_point_cloud creates proper Open3D point cloud.""" point_cloud = build_point_cloud(sample_points, sample_colors) - assert isinstance(point_cloud, o3d.geometry.PointCloud) + assert type(point_cloud).__name__ == "PointCloud" assert len(point_cloud.points) == len(sample_points) assert len(point_cloud.colors) == len(sample_colors) assert np.allclose(np.asarray(point_cloud.points), sample_points) @@ -220,7 +220,7 @@ def test_view_point_cloud(self, mock_draw, sample_points, sample_colors): mock_draw.assert_called_once() args = mock_draw.call_args[0][0] assert len(args) == 1 - assert isinstance(args[0], o3d.geometry.PointCloud) + assert type(args[0]).__name__ == "PointCloud" @patch("open3d.visualization.rendering.OffscreenRenderer") def test_render_point_cloud( diff --git a/tests/test_yolo.py b/tests/test_yolo.py index 2fc45fe9..87e13296 100644 --- a/tests/test_yolo.py +++ b/tests/test_yolo.py @@ -4,6 +4,18 @@ import pandas as pd +# --------------------------------------------------------------------------- +# Try importing real optional C-extensions first so they get cached in +# sys.modules. This prevents the stub block below from replacing a real +# library that IS available in the environment (e.g. open3d), which would +# otherwise leak a MagicMock into other test modules like test_lidar.py. +# --------------------------------------------------------------------------- +for _real in ("open3d", "supervision"): + try: + __import__(_real) + except ImportError: + pass + # --------------------------------------------------------------------------- # Stub out heavy optional C-extensions that are not available in the test # environment (open3d, tqdm, etc.) before importing any perceptionmetrics module.