etianen / logot Goto Github PK
View Code? Open in Web Editor NEWTest whether your code is logging correctly ๐ชต
Home Page: https://logot.readthedocs.io
License: MIT License
Test whether your code is logging correctly ๐ชต
Home Page: https://logot.readthedocs.io
License: MIT License
With using doctest you can use ...
to mean regex-like .*
catchall.
When converting to logot I stumbled upon AssertionError: Not logged:
until realizing I had ...
inside the expected output.
I try to use doctest only in my code (with occasional unittest.DoctestRunner
) and it's always a hassle to capture log output, because doctest clones the logger instances transparently (or something).
Does it support structlog?
This would require capturing name
and add a new name
argument to the logged
APIs.
The twisted
library looks like a good candidate for a 3rd-party async integration.
This would allow asserting that an exception had been logged. Supporting bool | BaseException
for the match would be ideal.
False
- No exceptionTrue
- Any exceptiomBaseException
- EqualityNone
- AnythingA logged.exception()
helper would complete the feature.
The anyio
library looks like a good candidate for a 3rd-party async integration.
Thanks for your work.
Is it possible to configure loguru
or does logot
only work with a pre-configured default logger?
# test_logger.py
import sys
from typing import Callable
import pytest
from logot import Logot, logged
from logot.loguru import LoguruCapturer
from loguru import logger
from rich.logging import RichHandler
@pytest.fixture(scope="session")
def logot_capturer() -> Callable[[], LoguruCapturer]:
return LoguruCapturer
def test_capture(logot: Logot):
"""
Works
"""
# Log an error message with the default logger
logger.info("foo bar")
logot.assert_logged(logged.info("foo bar"))
def test_capture_setup_logger(logot: Logot):
"""
Does not work
"""
# Remove all handlers added so far, including the default one.
logger.remove()
# Console handler
logger.add(sink=sys.stderr, level="DEBUG", format="{message}")
# Log an error message
logger.info("foo bar")
logot.assert_logged(logged.info("foo bar"))
def test_capture_setup_logger_rich(logot: Logot):
"""
Does not work
"""
# Remove all handlers added so far, including the default one.
logger.remove()
# Console handler with rich formatting
logger.add(
sink=RichHandler(
log_time_format="[%X]",
rich_tracebacks=True,
tracebacks_show_locals=True,
),
level="DEBUG",
format="{message}",
)
# Log an error message
logger.info("foo bar")
logot.assert_logged(logged.info("foo bar"))
Errors:
$ test_capture_setup_logger
AssertionError: Not logged:
[INFO] foo bar
Captured stderr call:
foo bar
$ test_capture_setup_logger_rich
AssertionError: Not logged:
[INFO] foo bar
Captured stderr call:
[01:02:03] INFO foo bar test_logger.py:42
Loguru docs:
You should remove() it first if you plan to add() another handler logging messages to the console, otherwise you may end up with duplicated logs.
Once we support trio
via #78, tornado
support should be easy.
Supporting a basic loguru integration would be very easy by providing a context manager via a helper func using their LogHandler
integration.
Alternatively, a Logot
subclass called Logurot
would be cheese and fun. That would allow the pytest
plugin to provide a logurot
fixture too (if loguru
is installed).
This would need to be a recursive partial match.
The tornado
library looks like a good candidate for a 3rd-party async integration.
Originally intended as be part of #28, this has been moved to a separate issue following discussion with loguru
devs in Delgan/loguru#1072. ๐
Support .format()
-style placeholders like this:
from logot.contrib.loguru import logged
logot.wait_for(logged.info("Hello {}"))
Support matching structured data like this (requires #25):
logot.wait_for(
logged.bind(foo="bar").info("Hello {}")
)
Parsing of the format-style placeholders should be nice and easy using string.Formatter.parse()
. Probably easier than the normal %
-style placeholder parsing!
This can be used to create repetitions of log patterns.
Use this in the why test logging example like this:
from logot import Logot, logged
def test_poll_daemon(logot: Logot) -> None:
app.start_poll()
logot.wait_for(
(logged.info("Poll started")) >> logged.info("Poll finished")) * 3
)
Link to the log pattern matching docs from this example.
Implement with _from_compose
to correctly flatten _OrderedAllLogged
.
This would make it much easier to get started with unittest
!
We can support trio by allowing the async waiter implementation to be customized in the Logot
constructor.
It's a big heavy framework we don't always need to import. Since we're only importing 3rd-party libs when actually used, it would be ideal to treat heavyweight stdlib modules the same.
Since asyncio
is the default async waiter, probably a lazy import is best to keep the default async waiter zero-config.
The logbook
library looks well-supported and compatible with logot
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.