Skip to content
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 @@ -261,6 +261,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.
6 changes: 0 additions & 6 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
coverage:
status:
project: true
patch: true
changes: true

comment: off
2 changes: 1 addition & 1 deletion src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,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
4 changes: 2 additions & 2 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def pytest_addoption(parser):
dest="maxfail",
const=1,
help="exit instantly on first error or failed test.",
),
)
group._addoption(
"--maxfail",
metavar="num",
Expand Down Expand Up @@ -123,7 +123,7 @@ def pytest_addoption(parser):
"--co",
action="store_true",
help="only collect tests, don't execute them.",
),
)
group.addoption(
"--pyargs",
action="store_true",
Expand Down
5 changes: 5 additions & 0 deletions testing/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,3 +1532,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