diff --git a/tests/mocks/mock_dynamixel.py b/tests/mocks/mock_dynamixel.py index baf5a0ab..5549cf18 100644 --- a/tests/mocks/mock_dynamixel.py +++ b/tests/mocks/mock_dynamixel.py @@ -263,13 +263,18 @@ class MockStatusPacket(MockDynamixelPacketv2): class MockPortHandler(dxl.PortHandler): - def setupPort(self, baud): # noqa: N802 + """ + This class overwrite the 'setupPort' method of the dynamixel PortHandler because it can specify + baudrates that are not supported with a serial port on MacOS. + """ + + def setupPort(self, cflag_baud): # noqa: N802 if self.is_open: self.closePort() self.ser = serial.Serial( port=self.port_name, - # baudrate=self.baudrate, <- This is forbidden for ttys ports (on macos at least) + # baudrate=self.baudrate, <- This will fail on MacOS # parity = serial.PARITY_ODD, # stopbits = serial.STOPBITS_TWO, bytesize=serial.EIGHTBITS, diff --git a/tests/motors/test_dynamixel.py b/tests/motors/test_dynamixel.py index 37bb0b46..77f6bd73 100644 --- a/tests/motors/test_dynamixel.py +++ b/tests/motors/test_dynamixel.py @@ -1,3 +1,4 @@ +import sys from unittest.mock import patch import dynamixel_sdk as dxl @@ -9,12 +10,16 @@ from tests.mocks.mock_dynamixel import MockInstructionPacket, MockMotors, MockPo @pytest.fixture(autouse=True) def patch_port_handler(): - with patch.object(dxl, "PortHandler", MockPortHandler): - yield # Patch is applied for the duration of each test + if sys.platform == "darwin": + with patch.object(dxl, "PortHandler", MockPortHandler): + yield + else: + yield +@pytest.mark.skipif(sys.platform != "darwin", reason=f"No patching needed on {sys.platform=}") def test_autouse_patch(): - """Ensure that the autouse fixture correctly patches dxl.PortHandler with MockPortHandler.""" + """Ensures that the autouse fixture correctly patches dxl.PortHandler with MockPortHandler.""" assert dxl.PortHandler is MockPortHandler