scripts: pytest: remove logging configuration

Remove log.py and by this logging configuration from
pytest-harness-plugin. Instead use pytest options for setting verbosity
and format of printed logs. Thanks to this management of verbosity
level can be easier for users.

Signed-off-by: Piotr Golyzniak <piotr.golyzniak@nordicsemi.no>
This commit is contained in:
Piotr Golyzniak 2023-08-04 17:20:31 +02:00 committed by Anas Nashif
commit a31b24372c
3 changed files with 10 additions and 78 deletions

View file

@ -1,71 +0,0 @@
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import logging.config
import os
import pytest
def configure_logging(config: pytest.Config) -> None:
"""Configure logging."""
output_dir = config.option.output_dir
os.makedirs(output_dir, exist_ok=True)
log_file = os.path.join(output_dir, 'twister_harness.log')
if hasattr(config, 'workerinput'):
worker_id = config.workerinput['workerid']
log_file = os.path.join(output_dir, f'twister_harness_{worker_id}.log')
log_format = '%(asctime)s:%(levelname)s:%(name)s: %(message)s'
log_level = config.getoption('--log-level') or config.getini('log_level') or logging.INFO
log_file = config.getoption('--log-file') or config.getini('log_file') or log_file
log_format = config.getini('log_cli_format') or log_format
default_config = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': log_format,
},
'simply': {
'format': '%(asctime)s.%(msecs)d:%(levelname)s: %(message)s',
'datefmt': '%H:%M:%S'
}
},
'handlers': {
'file': {
'class': 'logging.FileHandler',
'level': 'DEBUG',
'formatter': 'standard',
'filters': [],
'filename': log_file,
'encoding': 'utf8',
'mode': 'w'
},
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG',
'formatter': 'simply',
'filters': [],
}
},
'loggers': {
'': {
'handlers': ['console', 'file'],
'level': 'WARNING',
'propagate': False
},
'twister_harness': {
'handlers': ['console', 'file'],
'level': log_level,
'propagate': False,
}
}
}
logging.config.dictConfig(default_config)

View file

@ -10,7 +10,6 @@ from pathlib import Path
import pytest
from twister_harness.log import configure_logging
from twister_harness.twister_harness_config import TwisterHarnessConfig
logger = logging.getLogger(__name__)
@ -135,8 +134,6 @@ def pytest_configure(config: pytest.Config):
# create output directory if not exists
os.makedirs(config.option.output_dir, exist_ok=True)
configure_logging(config)
config.twister_harness_config = TwisterHarnessConfig.create(config) # type: ignore

View file

@ -227,6 +227,7 @@ class Pytest(Harness):
self.running_dir = instance.build_dir
self.source_dir = instance.testsuite.source_dir
self.report_file = os.path.join(self.running_dir, 'report.xml')
self.pytest_log_file_path = os.path.join(self.running_dir, 'twister_harness.log')
self.reserved_serial = None
def pytest_run(self, timeout):
@ -249,18 +250,23 @@ class Pytest(Harness):
command = [
'pytest',
'--twister-harness',
'-s',
'-q',
'-s', '-v',
os.path.join(self.source_dir, pytest_root),
f'--build-dir={self.running_dir}',
f'--junit-xml={self.report_file}'
f'--junit-xml={self.report_file}',
'--log-file-level=DEBUG',
'--log-file-format=%(asctime)s.%(msecs)d:%(levelname)s:%(name)s: %(message)s',
f'--log-file={self.pytest_log_file_path}'
]
command.extend(pytest_args)
handler: Handler = self.instance.handler
if handler.options.verbose > 1:
command.append('--log-level=DEBUG')
command.extend([
'--log-cli-level=DEBUG',
'--log-cli-format=%(levelname)s: %(message)s'
])
if handler.type_str == 'device':
command.extend(