Skip to content

Commit 6f2943c

Browse files
authored
Merge pull request #6558 from gavento/patch-1
Make EncodedFile.write() return the return value from inner write()
2 parents 09ab5fd + 5e15c86 commit 6f2943c

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ Tim Hoffmann
256256
Tim Strazny
257257
Tom Dalton
258258
Tom Viner
259+
Tomáš Gavenčiak
259260
Tomer Keren
260261
Trevor Bekolay
261262
Tyler Goodlet

changelog/6557.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make capture output streams ``.write()`` method return the same return value from original streams.

src/_pytest/capture.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def write(self, obj):
424424
raise TypeError(
425425
"write() argument must be str, not {}".format(type(obj).__name__)
426426
)
427-
self.buffer.write(obj)
427+
return self.buffer.write(obj)
428428

429429
def writelines(self, linelist):
430430
data = "".join(linelist)

testing/test_capture.py

+5
Original file line numberDiff line numberDiff line change
@@ -1492,3 +1492,8 @@ def test_fails():
14921492
result_with_capture.stdout.fnmatch_lines(
14931493
["E * TypeError: write() argument must be str, not bytes"]
14941494
)
1495+
1496+
1497+
def test_stderr_write_returns_len(capsys):
1498+
"""Write on Encoded files, namely captured stderr, should return number of characters written."""
1499+
assert sys.stderr.write("Foo") == 3

0 commit comments

Comments
 (0)