diff --git a/scripts/tests/twister_blackbox/conftest.py b/scripts/tests/twister_blackbox/conftest.py index 11429319b96c03..1271af06694f1d 100644 --- a/scripts/tests/twister_blackbox/conftest.py +++ b/scripts/tests/twister_blackbox/conftest.py @@ -37,6 +37,11 @@ def zephyr_test_directory(): @pytest.fixture def clear_log(): + # clear_log is used by pytest fixture + # However, clear_log_in_test is prepared to be used directly in the code, wherever required + clear_log_in_test() + +def clear_log_in_test(): # Required to fix the pytest logging error # See: https://github.com/pytest-dev/pytest/issues/5502 loggers = [logging.getLogger()] \ diff --git a/scripts/tests/twister_blackbox/test_hardwaremap.py b/scripts/tests/twister_blackbox/test_hardwaremap.py index c1efd5be495310..c1f6ff1eaf8105 100644 --- a/scripts/tests/twister_blackbox/test_hardwaremap.py +++ b/scripts/tests/twister_blackbox/test_hardwaremap.py @@ -5,14 +5,13 @@ """ Blackbox tests for twister's command line functions """ -import logging import importlib import mock import os import pytest import sys -from conftest import ZEPHYR_BASE, testsuite_filename_mock +from conftest import ZEPHYR_BASE, testsuite_filename_mock, clear_log_in_test from twisterlib.testplan import TestPlan sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister/twisterlib")) @@ -155,14 +154,7 @@ def mocked_comports(): os.remove(path) assert str(sys_exit.value) == '0' - loggers = [logging.getLogger()] + \ - list(logging.Logger.manager.loggerDict.values()) + \ - [logging.getLogger(name) for \ - name in logging.root.manager.loggerDict] - for logger in loggers: - handlers = getattr(logger, 'handlers', []) - for handler in handlers: - logger.removeHandler(handler) + clear_log_in_test() @pytest.mark.parametrize( ('manufacturer', 'product', 'serial', 'runner'),