Skip to content

Commit

Permalink
scripts: twister_blackbox: Added the ability to clear log from the code
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
KamilxPaszkiet authored and mcscholtz committed Jan 24, 2024
1 parent b25f72b commit bdd2c6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 5 additions & 0 deletions scripts/tests/twister_blackbox/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()] \
Expand Down
12 changes: 2 additions & 10 deletions scripts/tests/twister_blackbox/test_hardwaremap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit bdd2c6f

Please sign in to comment.