Capturing logs with log_capture in behave
See original GitHub issueProblem
I run my test with behave (https://behave.readthedocs.io/en/stable/api.html?highlight=log_capture#logging-capture) and after changing to the loguru my tests fail.
I have read this post Issue 59 (regarding basically the same but with pytest), and I understand that loguru doesn’t use standardlib logging which behave log capture probably utilizes, and the way to solve the problem is to propagte the logs to the logging lib
however, I don’t understand how to replicate the fix.
I tried using the fixture in an analogous way but it didn’t seem to work:
Example of what I tried
environment.py
from api.features.fixtures import log_capture_fix
def before_all(context):
use_fixture(log_capture_fix, context)
context.config.setup_logging()
fixtures.py
import logging
from behave import fixture
from loguru import logger
@fixture
def log_capture_fix(context):
class PropogateHandler(logging.Handler):
def emit(self, record):
logging.getLogger(record.name).handle(record)
handler_id = logger.add(PropogateHandler(), format="{message} {extra}")
yield context.log_capture
logger.remove(handler_id)
Could you help me configure this properly, or point me in the right directions?
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Logging not captured on behave steps - Stack Overflow
I am using the python behave module. Any ideas? I have tried enabling and disabling logcapture when I run behave but it makes...
Read more >Command-Line Arguments - Behave
Capture logging. All logging during a step will be captured and displayed in the event of a failure. This is the default behaviour....
Read more >Capturing logs with log_capture in behave - Bountysource
Problem. I run my test with behave (https://behave.readthedocs.io/en/stable/api.html?highlight=log_capture#logging-capture) and after ...
Read more >behave Documentation - Read the Docs
This switch is used to override a configuration file setting. --no-logcapture. Don't capture logging. Logging configuration will be left intact.
Read more >Behave - Command Line - Tutorialspoint
This is an in-built characteristic and can overrule a configuration file setting. --no-logcapture. Exclude log from capturing. --logcapture. Include log ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah! Right that might be it 🚀 In hindsight it seems kinda obvious 🤦 . Anyway, thank you very much for helping out Delgan. I will fix it tomorrow to run in correct order during tests, and update here how it went (though I wouldn’t expect further problems now 😄)
UPDATE: Yep. Running the init() at the beggining fo the fixture solved the problem. Once again, thank you very much Delgan 😄
I’m closing this issue since it’s resolved, then. 👍