def kill_test_logger ( logger ) : for h in list ( logger . handlers ) : logger . removeHandler ( h ) if isinstance ( h , logging . FileHandler ) : h . close ( )
killing logging handlers in python
Cleans up a test logger object by removing all of its handlers .
def kill_test_logger(logger):
    """Cleans up a test logger object by removing all of its handlers.

    Args:
        logger: The logging object to clean up.
    """
    for h in list(logger.handlers):
        logger.removeHandler(h)
        if isinstance(h, logging.FileHandler):
            h.close()