generated from dataforgoodfr/d4g-project-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add logging and logging once tests
- Loading branch information
1 parent
55e8003
commit 0cd0df2
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |