-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mocked stdio are not like the real thing #24
Comments
Thanks for the ticket, John. You're right, the It would be great to make the |
I've been building real-ish classes over at https://github.com/bskinn/stdio-mgr/pulls , especially bskinn/stdio-mgr#25 and bskinn/stdio-mgr#26 . Examples of scenarios where the simple mocks dont work are shown at bskinn/stdio-mgr#24 |
Interesting! Another approach could be to use Both of these approaches only work for Python 3, which would be a problem for now, but not in the long term. I guess I could try to implement the whole thing here in a 2/3-compliant way while peeking into your pull requests for What are your thoughts on those options? |
There are backports of https://pypi.org/search/?q=contextlib , if you went down that path. @bskinn might be better to answer why he created stdio-mgr instead of using contextlib. My guess is that the stdin part, and linking it with stdout, is where the value is. Also I think stdio-mgr could be Python 2 compatible without much effort. I would be happy to attempt it, if @bskinn would accept it. |
Aha, I just realized that This makes studio-mgr a more attractive option, especially if it would become Python 2 compatible. Could you ping me when the two MRs mentioned above are merged and I will try to make my mind meanwhile? |
The main motivation was definitely the capture of stdin, to enable me to write fully in-context CLI tests that require simulation of user input; e.g., here. I looked around, but didn't find anything that seemed to do what I wanted, so I made it (imperfectly) myself. I've appreciated @jayvdb's help in converting it to a more accurate match to the actual stdio objects in I'm pretty sure I could have used the stdout/stderr redirect tools from either
bskinn/stdio-mgr#4 is badly written (is really a note-to-self), its intent is to enable something like this, where the user could select to mock only one or two of the streams, instead of being forced to mock all three.
Agreed, it would probably not be hard, though I have ~zero experience with 2/3 compat. @jayvdb, if you're willing to continue to pitch in with maintenance (I really need to get CONTRIBUTORS and AUTHORS files put together...), I'm okay with trying to add Python 2 support. I'd ask, though -- how far beyond 1/1/2020 are you planning on keeping Py2 support, since pytest itself has already dropped support in v5? At this point, it seems like the returns would diminish rapidly. |
Hi @bskinn, thank you for the background!
Yeah, very good question. It can't really be very far. I have some code of my own that has to still support Python 2 because of reasons but that's going to go away before 2020 and I would not want to keep Python 2 compatibility around just for that anyway, I'd rather pin Anyway, I don't feel very comfortable asking anyone to work on Python 2 compatibility in their code at this point. Unless it's really easy to make |
I poked at 2.7 a bit ... it needs I suspect there's going to be a lot of pin-and-pray going on with 2.7-locked codebases. Hopefully it doesn't lead to some major security apocalypse down the line. 😞 |
I maintain a few large py2/3 codebases, and pin-and-pray is going to be a notable concept very soon. I would aim for one good release with py2, then drop it. Users can then pin it. The benefit is a lot of projects can replace their py2 stdio code with stdio-mgr, without killing py2 explicitly. That concentrates any py2 users on stdio-mgr, distributing the effort required to keep it alive. Or it will die quietly of old age. |
Hiya @kvas-it , those PRs were merged, and bskinn/stdio-mgr#53 will add extra opportunity to customise the behaviour by allowing subclasses. This would be a good point to get some requirements from you about what features you would want, so we could prioritise them for the next release. There is quite a long list of issues at https://github.com/bskinn/stdio-mgr/issues , mostly feature ideas. |
Thank you @jayvdb! I don't have much to add in terms of requirements apart from the fact that for now So I guess I just need to make up my mind about Python 2. So the best looking option seems to be a breaking major release that would be Python 3 only and advising people to pin it at the old version for Python 2 support. |
To note, per discussion at bskinn/stdio-mgr#34, we're still contemplating an attempt at a 2.7 backport at some point. |
Yeah, thank you for that. Don't consider me strongly in favor of it though. I mean, it would make my life easier here but I'm not sure it's a good use of your time, guys ;) |
The project uses It still doesn't have On the bright side it's been so long since this PR was opened that everything that's needed from the standard library is now available. |
All of the
sys.std*
are of typeio.TextIOWrapper
which has a.buffer
of typeio.BufferedReader
.Without the mock implementing TextIOWrapper, it wont work with any the code being tested that needs to access those buffers , or any of the other features of the real stdii handles which are not implemented by
StringIO
, and alsoStringIO
exposes methods which are not valid on the real stdio handles.Another important feature of the real stdio handles is the new
reconfigure
in py37+, which is useful to force a sensible encoding on a stdio stream.The text was updated successfully, but these errors were encountered: