Skip to content

Commit 114548e

Browse files
KamilxPaszkietnashif
authored andcommitted
scripts: twister_blackbox: Added the ability to clear log from the code
clear_log is used as a fixture by pytest. We need to be able to call it from the code level. Example of use in the file test_harwaremap.py line 157. Signed-off-by: Paszkiet Kamil <kamilx.paszkiet@intel.com>
1 parent 117dc55 commit 114548e

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

scripts/tests/twister_blackbox/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def zephyr_test_directory():
3737

3838
@pytest.fixture
3939
def clear_log():
40+
# clear_log is used by pytest fixture
41+
# However, clear_log_in_test is prepared to be used directly in the code, wherever required
42+
clear_log_in_test()
43+
44+
def clear_log_in_test():
4045
# Required to fix the pytest logging error
4146
# See: https://github.com/pytest-dev/pytest/issues/5502
4247
loggers = [logging.getLogger()] \

scripts/tests/twister_blackbox/test_hardwaremap.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
"""
66
Blackbox tests for twister's command line functions
77
"""
8-
import logging
98
import importlib
109
import mock
1110
import os
1211
import pytest
1312
import sys
1413

15-
from conftest import ZEPHYR_BASE, testsuite_filename_mock
14+
from conftest import ZEPHYR_BASE, testsuite_filename_mock, clear_log_in_test
1615
from twisterlib.testplan import TestPlan
1716

1817
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister/twisterlib"))
@@ -155,14 +154,7 @@ def mocked_comports():
155154
os.remove(path)
156155

157156
assert str(sys_exit.value) == '0'
158-
loggers = [logging.getLogger()] + \
159-
list(logging.Logger.manager.loggerDict.values()) + \
160-
[logging.getLogger(name) for \
161-
name in logging.root.manager.loggerDict]
162-
for logger in loggers:
163-
handlers = getattr(logger, 'handlers', [])
164-
for handler in handlers:
165-
logger.removeHandler(handler)
157+
clear_log_in_test()
166158

167159
@pytest.mark.parametrize(
168160
('manufacturer', 'product', 'serial', 'runner'),

0 commit comments

Comments
 (0)