bugfix: don't use sys.stdout as a default arg value#16541
Merged
Conversation
cc5483c to
1ed8b9f
Compare
1ed8b9f to
df5585b
Compare
After migrating to `travis-ci.com`, we saw I/O issues in our tests --
tests that relied on `capfd` and `capsys` were failing. We've also seen
this in GitHub actions, and it's kept us from switching to them so far.
Turns out that the issue is that using streams like `sys.stdout` as
default arguments doesn't play well with `pytest` and output redirection,
as `pytest` changes the values of `sys.stdout` and `sys.stderr`. if these
values are evaluated before output redirection (as they are when used as
default arg values), output won't be captured properly later.
- [x] replace all stream default arg values with `None`, and only assign stream
values inside functions.
- [x] fix tests we didn't notice were relying on this erroneous behavior
df5585b to
11afc06
Compare
alalazo
approved these changes
May 9, 2020
Member
|
🥳 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After migrating to
travis-ci.com, we saw I/O issues in our tests -- tests that relied oncapfdandcapsyswere failing. We've also seen this in GitHub actions, and it's kept us from switching to them so far.Turns out that the issue is that using streams like
sys.stdoutas default arguments doesn't play well withpytestand output redirection, aspytestchanges the values ofsys.stdoutandsys.stderr. if these values are evaluated before output redirection (as they are when used as default arg values), output won't be captured properly later.None, and only assign stream values inside functions.