Skip to content

Commit

Permalink
Added test_reporter_utils_logger_config.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wwakabobik committed Aug 29, 2024
1 parent 3674308 commit 86becd9
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/utils/test_reporter_utils_logger_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
"""Tests for the logger_config module"""

from logging import DEBUG, INFO, WARNING, ERROR, FATAL, FileHandler, StreamHandler
from random import choice, randint

from faker import Faker

from testrail_api_reporter.utils.logger_config import setup_logger, DEFAULT_LOGGING_LEVEL


fake = Faker()


def test_setup_logger_default_level(caplog):
"""Init logger with default level"""
log_file = fake.file_name(extension="log")
logger = setup_logger(fake.name(), str(log_file))

assert logger.level == DEFAULT_LOGGING_LEVEL
assert logger.level == DEBUG

assert len(logger.handlers) == 2
assert isinstance(logger.handlers[0], FileHandler)
assert isinstance(logger.handlers[1], StreamHandler)

message = str(fake.random_letters(randint(1, 10))) * randint(1, 10)
logger.debug(message)
with open(log_file, "r") as f:
assert message in f.read()
assert message in caplog.text


def test_setup_logger_custom_level(tmp_path):
"""Init logger with any other level"""
log_file = fake.file_name(extension="log")
log_level = choice((INFO, WARNING, ERROR, FATAL))
logger = setup_logger(fake.name(), str(log_file), level=log_level)

assert logger.level == log_level

0 comments on commit 86becd9

Please sign in to comment.