Mock robots (WIP segmentation fault)

This commit is contained in:
Remi Cadene
2024-09-12 01:43:32 +02:00
parent 4151630c24
commit 53ebf9cf9f
3 changed files with 28 additions and 6 deletions

View File

@@ -9,7 +9,6 @@ pytest -sx tests/test_motors.py::test_find_port
pytest -sx tests/test_motors.py::test_motors_bus
```
Example of running test on real dynamixel motors connected to the computer:
```bash
pytest -sx tests/test_motors.py::test_motors_bus[dynamixel]

View File

@@ -1,10 +1,27 @@
"""
Tests meant to be used locally and launched manually.
Tests for physical robots and their mocked versions.
If the physical robots are not connected to the computer, or not working,
the test will be skipped.
Example usage:
Example of running a specific test:
```bash
pytest -sx tests/test_robots.py::test_robot
```
Example of running test on real robots connected to the computer:
```bash
pytest -sx tests/test_robots.py::test_robot[koch]
pytest -sx tests/test_robots.py::test_robot[koch_bimanual]
pytest -sx tests/test_robots.py::test_robot[aloha]
```
Example of running test on a mocked version of robots:
```bash
pytest -sx -k "mocked_koch" tests/test_robots.py::test_robot
pytest -sx -k "mocked_koch_bimanual" tests/test_robots.py::test_robot
pytest -sx -k "mocked_aloha" tests/test_robots.py::test_robot
```
"""
from pathlib import Path
@@ -12,12 +29,11 @@ from pathlib import Path
import pytest
import torch
from lerobot import available_robots
from lerobot.common.robot_devices.robots.factory import make_robot as make_robot_from_cfg
from lerobot.common.robot_devices.robots.utils import Robot
from lerobot.common.robot_devices.utils import RobotDeviceAlreadyConnectedError, RobotDeviceNotConnectedError
from lerobot.common.utils.utils import init_hydra_config
from tests.utils import ROBOT_CONFIG_PATH_TEMPLATE, require_robot
from tests.utils import ROBOT_CONFIG_PATH_TEMPLATE, TEST_ROBOT_TYPES, require_robot
def make_robot(robot_type: str, overrides: list[str] | None = None) -> Robot:
@@ -27,7 +43,7 @@ def make_robot(robot_type: str, overrides: list[str] | None = None) -> Robot:
return robot
@pytest.mark.parametrize("robot_type", available_robots)
@pytest.mark.parametrize("robot_type", TEST_ROBOT_TYPES)
@require_robot
def test_robot(tmpdir, request, robot_type):
# TODO(rcadene): measure fps in nightly?

View File

@@ -197,6 +197,13 @@ def require_robot(func):
mock_cameras(request)
mock_motors(request)
def mock_input(text):
print(text)
monkeypatch = request.getfixturevalue("monkeypatch")
# To run calibration without user input
monkeypatch.setattr("builtins.input", mock_input)
# Run test with a real robot. Skip test if robot connection fails.
else:
# `is_robot_available` is defined in `tests/conftest.py`