Skip to content

capsys + sys.stdout.buffer => AttributeError #1407

@asottile

Description

@asottile

Applicable versions where sys.stdout.buffer should exist and be a bytestream:

  • python3.x
import sys


def test(capsys):
    sys.stdout.buffer.write(b'hi\n')
    assert capsys.readouterr()[0] == 'hi\n'
$ py.test test.py
============================= test session starts ==============================
platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: /home/asottile/workspace/cheetah_lint, inifile: 
collected 1 items 

test.py F

=================================== FAILURES ===================================
_____________________________________ test _____________________________________

capsys = <_pytest.capture.CaptureFixture object at 0x7f15ca2cd320>

    def test(capsys):
>       sys.stdout.buffer.write(b'hi\n')
E       AttributeError: '_io.StringIO' object has no attribute 'buffer'

test.py:5: AttributeError
=========================== 1 failed in 0.01 seconds ===========================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions