From e878ed7ed09e4a571e5d270523497f5851bfd103 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Sun, 10 May 2026 18:11:55 +0200 Subject: [PATCH] Correct Log repeat. --- pymodbus/logging.py | 2 +- test/global/test_logging.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pymodbus/logging.py b/pymodbus/logging.py index 4fa24572e..c3c16518c 100644 --- a/pymodbus/logging.py +++ b/pymodbus/logging.py @@ -150,7 +150,7 @@ def build_msg(cls, txt, *args): if not cls.repeat_log: cls.repeat_log = True return "Repeating...." - return cls.last_log_text + return None @classmethod def info(cls, txt, *args): diff --git a/test/global/test_logging.py b/test/global/test_logging.py index 2ccc3b404..5d6b72b29 100644 --- a/test/global/test_logging.py +++ b/test/global/test_logging.py @@ -1,4 +1,5 @@ """Test datastore.""" +import contextlib import logging import os from unittest import mock @@ -21,7 +22,8 @@ class TestLogging: def teardown_class(cls): """Remove test file.""" if "CI" not in os.environ: # pragma: no cover - os.remove(cls.LOG_FILE) + with contextlib.suppress(FileNotFoundError): + os.remove(cls.LOG_FILE) def test_log_dont_call_build_msg(self): """Verify that build_msg is not called unnecessary.""" @@ -117,6 +119,13 @@ def test_log_get_frames(self): Log.transport_dump(Log.SEND_DATA, b'678', b'9') pymodbus_get_last_frames() + def test_log_repeat(self): + """Test repeating log Frames.""" + text = "msg being repeated." + assert text == Log.build_msg(text) + assert Log.build_msg(text) == "Repeating...." + assert not Log.build_msg(text) + def test_transport_dump(self): """Test transport_dump.""" pymodbus_apply_logging_config("error")