Feature request: use caplog with custom formatter
See original GitHub issueMy application uses a quite heavily customized logging formatter. Right now, the logging plugin only allows to specify the formats for the formatter, not completely replacing it. It would be nice if there was a clean way to provide a custom formatter.
This is the workaround I use for now, patching the plugin class on the module:
from _pytest import logging as pytest_logging
def pytest_configure(config):
config.pluginmanager.get_plugin('logging').LoggingPlugin = MyLoggingPlugin
class MyLoggingPlugin(pytest_logging.LoggingPlugin):
def __init__(self, config):
super().__init__(config)
self.formatter = MyCustomFormatter()
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Pytest caplog works with custom logger when created with a ...
I have been testing my custom loggers with Pytest. Created a custom logger from Yaml config file, and wrote the following test:
Read more >How to manage logging — pytest documentation
If desired the log and date format can be specified to anything that the ... To access logs from other stages, use the...
Read more >_pytest.logging module — pytest API documentation
Returns a list of a stripped down version of log records intended for use in assertion comparison. The format of the tuple is:...
Read more >loguru Documentation - Read the Docs
Loguru is a library which aims to bring enjoyable logging in Python. Did you ever feel lazy about configuring a logger and used...
Read more >Reference — pytest documentation
@pytest.fixture; config.cache; capsys; capsysbinary; capfd; capfdbinary; doctest_namespace; request; pytestconfig; record_property; caplog; monkeypatch ...
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 Free
Top 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
One option (definitely not optimal) would be to instantiate your custom formatter and set it explicitly on the caplog handler.
Perhaps this can be implemented as a hook:
Then you can do this in your root
conftest.py
file: