mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-18 10:10:08 +00:00
fix leaking imports in minimal testing
This commit is contained in:
+21
-6
@@ -17,24 +17,39 @@
|
||||
import traceback
|
||||
|
||||
import pytest
|
||||
from serial import SerialException
|
||||
|
||||
from lerobot.configs.types import FeatureType, PipelineFeatureType, PolicyFeature
|
||||
from lerobot.utils.import_utils import is_package_available
|
||||
from tests.utils import DEVICE
|
||||
|
||||
# Import fixture modules as plugins
|
||||
# Import fixture modules as plugins.
|
||||
# Fixtures that depend on optional packages are only registered when those packages are available,
|
||||
# so that tests can be collected and run even with a minimal install.
|
||||
pytest_plugins = [
|
||||
"tests.fixtures.dataset_factories",
|
||||
"tests.fixtures.files",
|
||||
"tests.fixtures.hub",
|
||||
"tests.fixtures.optimizers",
|
||||
]
|
||||
|
||||
if is_package_available("datasets"):
|
||||
pytest_plugins += [
|
||||
"tests.fixtures.dataset_factories",
|
||||
"tests.fixtures.files",
|
||||
"tests.fixtures.hub",
|
||||
]
|
||||
|
||||
|
||||
def pytest_collection_finish():
|
||||
print(f"\nTesting with {DEVICE=}")
|
||||
|
||||
|
||||
def _is_serial_exception(exc: Exception) -> bool:
|
||||
"""Check if an exception is a SerialException without requiring pyserial."""
|
||||
if not is_package_available("pyserial", import_name="serial"):
|
||||
return False
|
||||
from serial import SerialException
|
||||
|
||||
return isinstance(exc, SerialException)
|
||||
|
||||
|
||||
def _check_component_availability(component_type, available_components, make_component):
|
||||
"""Generic helper to check if a hardware component is available"""
|
||||
if component_type not in available_components:
|
||||
@@ -53,7 +68,7 @@ def _check_component_availability(component_type, available_components, make_com
|
||||
|
||||
if isinstance(e, ModuleNotFoundError):
|
||||
print(f"\nInstall module '{e.name}'")
|
||||
elif isinstance(e, SerialException):
|
||||
elif _is_serial_exception(e):
|
||||
print("\nNo physical device detected.")
|
||||
elif isinstance(e, ValueError) and "camera_index" in str(e):
|
||||
print("\nNo physical camera detected.")
|
||||
|
||||
Reference in New Issue
Block a user