-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
capture: Output in "Captured stdout" section but not available to test #6676
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
Comments
that's a user error - the module takes a different file object to the default |
So this is a small example to demonstrate the issue but the problem I’m experiencing is with a larger library that makes use of this style of passing sys.stdout to the print file parameter. Presumably so that a different file handler can be supplied if desired. Is the correct method in my tests to try to mock the libraries use of |
if the library does not ensure its taking the current stdout as a default, then it is broken in terms of stdout redirection and that "breakage" has to be worked around a potential way would be to wrap the library with a redirect_stdout contextmanager which replaces the default stdout object with one that lazily uses sys.stdout so that the library is tricked how feasible that is depends on the details of the library it should be noted, that |
Thanks for the help. I will do some research on how to get the current sys.stdout and work with the library maintainer on a pull request. That sounds like a better long term solution. In the meantime I’ll also adjust my code accordingly. |
btw, whats the library in question? |
NagiosPlugin https://github.com/mpounsett/nagiosplugin I had already raised an issue on that repo as well but wanted to check both avenues. |
I believe this may be the same issue as #5997 but in case not opened as a separate issue. When a module passes
sys.stdout
to theprint
function'sfile
parameter the output says it is captured but is not available to the test as an assertion.Minimal Code:
File:
helloworld.py
File:
test_helloworld.py
Test Results
PIP List
The text was updated successfully, but these errors were encountered: