From e7fd6fcf4b074c0bfed8e9c0919e1e425452dcd2 Mon Sep 17 00:00:00 2001 From: Alexander Presnyakov Date: Mon, 28 Apr 2025 19:20:48 +0000 Subject: [PATCH] Fix logging (trace level) in tests --- cmapi/cmapi_server/logging_management.py | 3 ++- cmapi/cmapi_server/test/unittest_global.py | 10 ++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cmapi/cmapi_server/logging_management.py b/cmapi/cmapi_server/logging_management.py index cffcae122..7979b19ff 100644 --- a/cmapi/cmapi_server/logging_management.py +++ b/cmapi/cmapi_server/logging_management.py @@ -104,7 +104,8 @@ def enable_console_logging(logger: logging.Logger) -> None: def config_cmapi_server_logging(): # add custom level TRACE only for develop purposes # could be activated using API endpoints or cli tool without relaunching - add_logging_level('TRACE', 5) + if not hasattr(logging, 'TRACE'): + add_logging_level('TRACE', 5) cherrypy._cplogging.LogManager.error = custom_cherrypy_error # reconfigure cherrypy.access log message format # Default access_log_format '{h} {l} {u} {t} "{r}" {s} {b} "{f}" "{a}"' diff --git a/cmapi/cmapi_server/test/unittest_global.py b/cmapi/cmapi_server/test/unittest_global.py index 57ec6c749..8f7864747 100644 --- a/cmapi/cmapi_server/test/unittest_global.py +++ b/cmapi/cmapi_server/test/unittest_global.py @@ -2,21 +2,14 @@ import logging import os import unittest from contextlib import contextmanager -from datetime import datetime, timedelta from shutil import copyfile from tempfile import TemporaryDirectory import cherrypy -from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives import serialization -from cryptography.hazmat.primitives.asymmetric import rsa -from cryptography import x509 -from cryptography.x509.oid import NameOID -from cryptography.hazmat.primitives import hashes - from cmapi_server import helpers from cmapi_server.constants import CMAPI_CONF_PATH from cmapi_server.controllers.dispatcher import dispatcher, jsonify_error +from cmapi_server.logging_management import config_cmapi_server_logging from cmapi_server.managers.process import MCSProcessManager from cmapi_server.managers.certificate import CertificateManager @@ -80,6 +73,7 @@ class BaseServerTestCase(unittest.TestCase): ) copyfile(cmapi_config_filename, self.cmapi_config_filename) copyfile(TEST_MCS_CONFIG_FILEPATH, self.mcs_config_filename) + config_cmapi_server_logging() self.app = cherrypy.tree.mount( root=None, config=self.cmapi_config_filename )