Skip to content

Commit

Permalink
tests: add logging and logging once tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelrince committed Dec 13, 2024
1 parent 55e8003 commit 0cd0df2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import logging

import pytest

from ecologits.log import logger


@pytest.mark.parametrize("logging_func", [
logger.debug,
logger.info,
logger.warning,
logger.error,
logger.critical
])
def test_logging(caplog, logging_func):
with caplog.at_level(logging.DEBUG, logger="ecologits"):
logging_func("test")
assert "test" in caplog.text


@pytest.mark.parametrize("logging_func", [
logger.debug_once,
logger.info_once,
logger.warning_once,
logger.error_once,
logger.critical_once
])
def test_logging_once(caplog, logging_func):
with caplog.at_level(logging.DEBUG, logger="ecologits"):
logging_func(f"test({logging_func.__name__})")
logging_func(f"test({logging_func.__name__})") # This shouldn't be logged
logging_func(f"test2({logging_func.__name__})")
assert len(caplog.records) == 2
assert "test" in caplog.text
assert "test2" in caplog.text

0 comments on commit 0cd0df2

Please sign in to comment.