Skip to content

Captured IO accepts bytes even tough it should not #4861

@mbra

Description

@mbra

On Python3, when output capturing is enabled, bytes are accepted where normaly only text would we accepted.

I am on Ubuntu 18.04 and using it's Python 3.6 packages with pytest 4.3.0.

Code:

# coding: utf-8

import sys as _sys


def test_output():
    _sys.stdout.write(b"foo")

With capturing:

=============================== test session starts ===============================
platform linux -- Python 3.6.6, pytest-4.3.0, py-1.6.0, pluggy-0.7.1
rootdir: /tmp/tmp.t1x157Dqyo, inifile:
plugins: localserver-0.5.0, httpbin-0.3.0, cov-2.6.0
collected 1 item                                                                  

test.py .                                                                   [100%]

============================ 1 passed in 0.00 seconds =============================

Without capturing:

=============================== test session starts ===============================
platform linux -- Python 3.6.6, pytest-4.3.0, py-1.6.0, pluggy-0.7.1
rootdir: /tmp/tmp.t1x157Dqyo, inifile:
plugins: localserver-0.5.0, httpbin-0.3.0, cov-2.6.0
collected 1 item                                                                  

test.py F

==================================== FAILURES =====================================
___________________________________ test_output ___________________________________

    def test_output():
>       _sys.stdout.write(b"foo")
E       TypeError: write() argument must be str, not bytes

test.py:7: TypeError
============================ 1 failed in 0.02 seconds =============================

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: capturerelated to the capture builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions