From 9c0d6c159ccf4b3f910b3b57aeb033a5e6691de3 Mon Sep 17 00:00:00 2001 From: Janick Martinez Esturo Date: Wed, 6 May 2026 10:44:12 +0200 Subject: [PATCH] fix(unit-tests): Prevent relative imports in tests Previously ncore/data/__init__.py was deleted after test execution due to bazel overwriting the package init file - disallow this in test targets and fix all relative imports to be absolute. --- bazel/pytest/defs.bzl | 1 + ncore/impl/data/stores_test.py | 2 +- ncore/impl/data/types_test.py | 3 +-- ncore/impl/data/util_test.py | 2 +- ncore/impl/data/v4/compat_test.py | 6 ++---- ncore/impl/data/v4/components_test.py | 3 +-- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/bazel/pytest/defs.bzl b/bazel/pytest/defs.bzl index 9faee1a4..6c0dad54 100644 --- a/bazel/pytest/defs.bzl +++ b/bazel/pytest/defs.bzl @@ -36,6 +36,7 @@ def pytest_test(name, srcs, python_versions = ["3.11", "3.8"], deps = [], args = "--capture=no", ] + args + ["$(location :%s)" % x for x in srcs], srcs_version = "PY3", + legacy_create_init = 0, deps = deps + [ requirement("pytest"), ], diff --git a/ncore/impl/data/stores_test.py b/ncore/impl/data/stores_test.py index 6a90f700..442f606e 100644 --- a/ncore/impl/data/stores_test.py +++ b/ncore/impl/data/stores_test.py @@ -24,7 +24,7 @@ import parameterized import zarr -from .stores import IndexedTarStore, consolidate_compressed_metadata, open_compressed_consolidated +from ncore.impl.data.stores import IndexedTarStore, consolidate_compressed_metadata, open_compressed_consolidated COMPRESSED_CONSOLIDATED_VALUES = [False, True] diff --git a/ncore/impl/data/types_test.py b/ncore/impl/data/types_test.py index 1e45843d..ae6479ab 100644 --- a/ncore/impl/data/types_test.py +++ b/ncore/impl/data/types_test.py @@ -21,8 +21,7 @@ import numpy.testing as npt from ncore.impl.common.transformations import PoseGraphInterpolator - -from .types import PointCloud +from ncore.impl.data.types import PointCloud class TestPointCloud(unittest.TestCase): diff --git a/ncore/impl/data/util_test.py b/ncore/impl/data/util_test.py index e36ff5ac..65710288 100644 --- a/ncore/impl/data/util_test.py +++ b/ncore/impl/data/util_test.py @@ -15,7 +15,7 @@ import unittest -from .util import closest_index_sorted +from ncore.impl.data.util import closest_index_sorted class TestClosestIndexSorted(unittest.TestCase): diff --git a/ncore/impl/data/v4/compat_test.py b/ncore/impl/data/v4/compat_test.py index a04f8ed4..d8721227 100644 --- a/ncore/impl/data/v4/compat_test.py +++ b/ncore/impl/data/v4/compat_test.py @@ -26,11 +26,9 @@ from ncore.impl.common.transformations import HalfClosedInterval from ncore.impl.common.util import unpack_optional -from ncore.impl.data.compat import RayBundleSensorPointCloudsSourceAdapter from ncore.impl.data.types import PointCloud, RowOffsetStructuredSpinningLidarModelParameters - -from .compat import SequenceLoaderV4 -from .components import ( +from ncore.impl.data.v4.compat import SequenceLoaderV4 +from ncore.impl.data.v4.components import ( IntrinsicsComponent, LidarSensorComponent, PointCloudsComponent, diff --git a/ncore/impl/data/v4/components_test.py b/ncore/impl/data/v4/components_test.py index 1345dc73..970a3664 100644 --- a/ncore/impl/data/v4/components_test.py +++ b/ncore/impl/data/v4/components_test.py @@ -41,8 +41,7 @@ RowOffsetStructuredSpinningLidarModelParameters, ShutterType, ) - -from .components import ( +from ncore.impl.data.v4.components import ( CameraSensorComponent, ComponentReader, ComponentWriter,