MCPcopy
hub / github.com/Delgan/loguru / test_lazy_function_executed_only_once

Function test_lazy_function_executed_only_once

tests/test_opt.py:156–169  ·  view source on GitHub ↗
(writer)

Source from the content-addressed store, hash-verified

154
155
156def test_lazy_function_executed_only_once(writer):
157 counter = 0
158
159 def laziness():
160 nonlocal counter
161 counter += 1
162 return counter
163
164 logger.add(writer, level=10, format="{level.name} => {message}")
165
166 logger.opt(lazy=True).info("1: {lazy} {lazy}", lazy=laziness)
167 logger.opt(lazy=True).info("2: {0} {0}", laziness)
168
169 assert writer.read() == "INFO => 1: 1 1\nINFO => 2: 2 2\n"
170
171
172def test_logging_within_lazy_function(writer):

Callers

nothing calls this directly

Calls 4

addMethod · 0.80
infoMethod · 0.80
optMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…