Closed Jayman2000 closed 11 months ago
I'm curious: why and when do you need
--buffer
?
I don’t know. I tried running the tests on my local system when I ran into #621. I tried using --buffer
as a part of my debugging process, and when it made things worse, I started investigating. I had only tried --buffer
because it was mentioned on some StackOverflow question that I had found.
Before this change, if certain tests were failing in certain ways, then running
python -m unittest --buffer
would cause anAttributeError
in theunittest
module itself.Here’s what
unittest
does when you use the--buffer
argument:sys.stdout
andsys.stderr
toStringIO
s.getvalue()
onsys.stdout
andsys.stderr
to get data from itsStringIO
s.tests/test_cli.py
has its ownRunContext
class that does something similar. Before this change, here’s what could happen:unittest
setssys.stdout
andsys.stderr
toStringIO
s.unittest
runs a test that usesRunContext
.RunContext
gets entered. It setssys.stdout
andsys.stderr
to its ownStringIO
s.RunContext
gets exited. It setssys.stdout
andsys.stderr
tosys.__stdout__
andsys.__stderr__
.unittest
assumes thatsys.stdout
is still set to one of itsStringIO
s, and runssys.stdout.getvalue()
.unittest
crashes with this error: