Open codeananda opened 2 months ago
Have you tried to call logger.complete()
before assert_no_errors_logged()
?
When enqueue=True
, messages are not immediately logged: they are added to a queue and processed by a background thread. I think your test is failing because when assert_no_errors_logged()
is called, not all logs reached the caplog
sink yet. Adding a call to logger.complete()
ensures there is no pending logs remaining.
Aha! Yes logger.complete()
makes it work. Thanks
But hmm, does this mean I always have to call logger.complete()
before assert_no_errors_logged()
?
But hmm, does this mean I always have to call
logger.complete()
beforeassert_no_errors_logged()
?
Maybe that works as well if logger.complete()
is called at the beginning of assert_no_errors_logged()
?
You can also turn off the enqueue
option for such simple tests.
In
conftest.py
I have redefined caplog as per loguru's docs. I haveenqueue=True
because some of my code uses multiprocessing.I have a basic test which works when
enqueue=False
but not whenenqueue=True
. It works if I copy/paste the contents ofassert_no_errors_logged
underneath the test. But if I callassert_no_errors_logged
, pytest complains. This is not an issue ifenqueue=False
.Error