Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #111 +/- ##
==========================================
+ Coverage 94.31% 94.45% +0.13%
==========================================
Files 13 13
Lines 845 865 +20
==========================================
+ Hits 797 817 +20
Misses 48 48
🚀 New features to boost your workflow:
|
| class ToLogger(io.StringIO): | ||
| def write(self, s: str) -> int: | ||
| get_logger("selftest.stderr").warning(s) | ||
| return len(s) | ||
|
|
There was a problem hiding this comment.
Is that a valid usecase? I'd argue that if someone wants to simply print to stderr we shouldn't force any additional formatting or infrastructure on him. If we discard that usecase, this entire PR can be simplified to handler = logging._stdErrHandler().
I'd strongly argue that this is something that we shouldn't be concerned about, since this test would fail even using plain stdlib logging (which falls back to logging._stdErrHandler if nothing else is defined):
import sys
import logging
import io
class ToLogger(io.StringIO):
def write(self, s: str) -> int:
logging.getLogger("selftest.stderr").warning(s)
return len(s)
sys.stderr = ToLogger()
logging.getLogger("selftest").warning("hello")also fails with a RecursionError.
|
In addtion to my comment above, I'd actually argue that it's the behavior of the If pytest is the only problem, one can simply set |
Summary: The plain log handler (used without rich) now writes to whatever
sys.stderris when a record is emitted, socontextlib.redirect_stderrand pytest'scapsysandcapfdcapture its output.Before this change,
_make_handlercreatedlogging.StreamHandler(), which stores thesys.stderrobject that exists when the handler is made. When scverse_misc.logging was imported before a redirect or before pytest swappedsys.stderr, log records went to the old stream and the capture missed them. The rich handler already followed the currentsys.stderr, so the two paths behaved differently.Changes:
writeandflushforward to the currentsys.stderr.redirect_stderrand checks that the message lands in the buffer. It fails on main.Found while moving mantispy and squidpy onto
scverse_misc.logging.