Skip to content
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

Make EncodedFile.write() return the return value from inner write() #6558

Merged
merged 1 commit into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ Tim Hoffmann
Tim Strazny
Tom Dalton
Tom Viner
Tomáš Gavenčiak
Tomer Keren
Trevor Bekolay
Tyler Goodlet
Expand Down
1 change: 1 addition & 0 deletions changelog/6557.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make capture output streams ``.write()`` method return the same return value from original streams.
2 changes: 1 addition & 1 deletion src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def write(self, obj):
raise TypeError(
"write() argument must be str, not {}".format(type(obj).__name__)
)
self.buffer.write(obj)
return self.buffer.write(obj)

def writelines(self, linelist):
data = "".join(linelist)
Expand Down
5 changes: 5 additions & 0 deletions testing/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -1492,3 +1492,8 @@ def test_fails():
result_with_capture.stdout.fnmatch_lines(
["E * TypeError: write() argument must be str, not bytes"]
)


def test_stderr_write_returns_len(capsys):
"""Write on Encoded files, namely captured stderr, should return number of characters written."""
assert sys.stderr.write("Foo") == 3