Skip to content

Commit

Permalink
tests/test_modbusrtudriver: mock serial instead of relying on port=None
Browse files Browse the repository at this point in the history
Since minimalmodbus 2.1.0, minimalmodbus.Instrument() [1] no longer
accepts port=None. Accepting this was never documented. The idea was
that port=None would be passed to serial.Serial(port=None), which
explicitly allows this [2].

Now that this is no longer allowed, stick to the original
port="/dev/tty0" in the test and mock serial.Serial, so it is not
actually opened.

[1] https://minimalmodbus.readthedocs.io/en/stable/apiminimalmodbus.html#minimalmodbus.Instrument
[2] https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial

Signed-off-by: Bastian Krause <bst@pengutronix.de>
  • Loading branch information
Bastian-Krause committed Jul 20, 2023
1 parent 39c2b0f commit 352191f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tests/test_modbusrtudriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ def test_resource_with_non_default_argument(target):

def test_driver(target, mocker):
pytest.importorskip("minimalmodbus")
mocker.patch('serial.Serial')

ModbusRTU(target, name=None, port="/dev/tty0", address=10)
driver = ModbusRTUDriver(target, name=None)

# Ensure pyserial will not try to open the port
driver.resource.port = None

target.activate(driver)

assert driver.instrument.serial.baudrate == 115200
Expand Down

0 comments on commit 352191f

Please sign in to comment.