hashtaghashtaghashtag Environment
- Python Version: 3.9
- Loguru Version: 0.7.2
- Pytest Version: 7.4.4
hashtaghashtaghashtag Description
I am encountering an issue with configuring Loguru to work in tandem with Pytest's --log-cli-level flag. Recently I start to switch logging from python native logging to Loguru. It's indeed simple and coll. However, I found when it goes to pytest, it became somehow confusing. My goal is to run Pytest with the flag --log-cli-level=INFO or --log-level=INFO and ensure that DEBUG level messages are not shown in the test output. However, despite various attempts and configurations, DEBUG messages are still being displayed.
hashtaghashtaghashtag Steps to Reproduce
- Write a test function that includes
loguru logger messages at various levels, including DEBUG.
- Run Pytest with the command:
python -m pytest -s tests --log-cli-level=INFO.
- Observe that
DEBUG messages are still appearing in the output.
hashtaghashtaghashtag What I've Tried
-
I've read through related GitHub issues (GHhashtag59 and GHhashtag474) and the official loguru documentation (
-
I've tried using a caplog fixture to integrate loguru logger with pytest's logging mechanism as shown below:
def caplog(caplog: LogCaptureFixture):
handler_id = logger.add(
caplog.handler,
format="{message}",
level=0,
filter=lambda record: record["level"].no >= caplog.handler.level,
enqueue=False,
)
yield caplog
logger.remove(handler_id)
-
I've also tried adding a reportlog fixture to handle log messages:
def reportlog(pytestconfig):
logging_plugin = pytestconfig.pluginmanager.getplugin("logging-plugin")
handler_id = logger.add(logging_plugin.report_handler, format="{message}")
yield
logger.remove(handler_id)
-
I've also try pytest-loguru, but also not getting what I want.
hashtaghashtaghashtag Expected Behavior
I would expect that running Pytest with --log-cli-level=INFO would result in DEBUG level messages being filtered out from the test output.
hashtaghashtaghashtag Actual Behavior
DEBUG level messages are still being displayed in the test output.
hashtaghashtaghashtag Request
Could you please provide guidance or a solution on how to configure loguru to respect the --log-cli-level=INFO flag in Pytest? Any assistance or insights into this issue would be greatly appreciated.
Thank you for your time and help.
)
hashtaghashtaghashtag Environment
hashtaghashtaghashtag Description
I am encountering an issue with configuring Loguru to work in tandem with Pytest's
--log-cli-levelflag. Recently I start to switch logging from python native logging to Loguru. It's indeed simple and coll. However, I found when it goes to pytest, it became somehow confusing. My goal is to run Pytest with the flag--log-cli-level=INFOor--log-level=INFOand ensure thatDEBUGlevel messages are not shown in the test output. However, despite various attempts and configurations,DEBUGmessages are still being displayed.hashtaghashtaghashtag Steps to Reproduce
logurulogger messages at various levels, includingDEBUG.python -m pytest -s tests --log-cli-level=INFO.DEBUGmessages are still appearing in the output.hashtaghashtaghashtag What I've Tried
I've read through related GitHub issues (GHhashtag59 and GHhashtag474) and the official
logurudocumentation (I've tried using a
caplogfixture to integratelogurulogger withpytest's logging mechanism as shown below:I've also tried adding a
reportlogfixture to handle log messages:I've also try
pytest-loguru, but also not getting what I want.hashtaghashtaghashtag Expected Behavior
I would expect that running Pytest with
--log-cli-level=INFOwould result inDEBUGlevel messages being filtered out from the test output.hashtaghashtaghashtag Actual Behavior
DEBUGlevel messages are still being displayed in the test output.hashtaghashtaghashtag Request
Could you please provide guidance or a solution on how to configure
loguruto respect the--log-cli-level=INFOflag in Pytest? Any assistance or insights into this issue would be greatly appreciated.Thank you for your time and help.
)