diff --git a/doc/changelog.d/3665.fixed.md b/doc/changelog.d/3665.fixed.md new file mode 100644 index 0000000000..aeb7a12621 --- /dev/null +++ b/doc/changelog.d/3665.fixed.md @@ -0,0 +1 @@ +fix: avoid com logging if not in debug mode \ No newline at end of file diff --git a/src/ansys/mapdl/core/mapdl_core.py b/src/ansys/mapdl/core/mapdl_core.py index 94626cf9c3..aa71a1d014 100644 --- a/src/ansys/mapdl/core/mapdl_core.py +++ b/src/ansys/mapdl/core/mapdl_core.py @@ -1401,7 +1401,9 @@ def __init__(self, parent): def __enter__(self): self._parent()._log.debug("Entering in non-interactive mode") - self._parent().com("Entering in non_interactive mode") + if self._parent().logger.logger.level <= logging.DEBUG: + # only commenting if on debug mode + self._parent().com("Entering in non_interactive mode") self._parent()._store_commands = True def __exit__(self, *args): diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index 3455e816d2..afad366a70 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -23,6 +23,7 @@ """Test MAPDL interface""" from datetime import datetime from importlib import reload +import logging import os from pathlib import Path import re @@ -2592,3 +2593,19 @@ def test_max_cmd_len_mapdlgrpc(mapdl): ): cmd = "a" * 640 mapdl._run(cmd) + + +def test_comment_on_debug_mode(mapdl, cleared): + loglevel = mapdl.logger.logger.level + + mapdl.logger.logger.level = logging.ERROR + with patch("ansys.mapdl.core.Mapdl.com") as mockcom: + mapdl.parameters["asdf"] = [1, 2, 3] + mockcom.assert_not_called() + + mapdl.logger.logger.level = logging.DEBUG + with patch("ansys.mapdl.core.Mapdl.com") as mockcom: + mapdl.parameters["asdf"] = [1, 2, 3] + mockcom.assert_called_once_with("Entering in non_interactive mode") + + mapdl.logger.logger.level = loglevel