shushlog/tests/test_supress.py
2023-10-02 22:46:29 +02:00

36 lines
913 B
Python

import pytest
import shush
def test_supress(caplog, logger):
@shush.suppress
def suppressed_func():
logger.info("This log should not appear")
def normal_func():
logger.info("This log should appear")
suppressed_func()
assert caplog.records == []
normal_func()
assert caplog.text == ('INFO test_logger:test_supress.py:12 '
'This log should appear\n')
@pytest.mark.anyio()
async def test_supress_async(caplog, logger):
@shush.suppress
async def suppressed_func_async():
logger.info("This log should not appear")
async def normal_func_async():
logger.info("This log should appear")
await suppressed_func_async()
assert caplog.records == []
await normal_func_async()
assert caplog.text == ('INFO test_logger:test_supress.py:29 '
'This log should appear\n')