From 0cd0df2b05690a73e2afa3f9353ef32c26e8f512 Mon Sep 17 00:00:00 2001 From: Samuel Rince Date: Fri, 13 Dec 2024 16:55:37 +0100 Subject: [PATCH] tests: add logging and logging once tests --- tests/test_logger.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_logger.py diff --git a/tests/test_logger.py b/tests/test_logger.py new file mode 100644 index 0000000..a7d9313 --- /dev/null +++ b/tests/test_logger.py @@ -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