From 923dcfd620f90934204fb1502b85b9b4fef2acf6 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 28 Mar 2014 09:46:38 +0100 Subject: [PATCH] cleanup and refine issue412 test (still failing on py33) --- _pytest/capture.py | 31 +++++-------------------------- testing/test_capture.py | 17 +++++++++-------- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/_pytest/capture.py b/_pytest/capture.py index 60771cdf6..25151ccd5 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -12,30 +12,7 @@ import contextlib import py import pytest -try: - from io import StringIO -except ImportError: - from StringIO import StringIO - -try: - from io import BytesIO -except ImportError: - class BytesIO(StringIO): - def write(self, data): - if isinstance(data, unicode): - raise TypeError("not a byte value: %r" % (data,)) - StringIO.write(self, data) - -if sys.version_info < (3, 0): - class TextIO(StringIO): - def write(self, data): - if not isinstance(data, unicode): - enc = getattr(self, '_encoding', 'UTF-8') - data = unicode(data, enc, 'replace') - StringIO.write(self, data) -else: - TextIO = StringIO - +from py.io import TextIO patchsysdict = {0: 'stdin', 1: 'stdout', 2: 'stderr'} @@ -232,7 +209,8 @@ class CaptureManager: error_capsysfderror = "cannot use capsys and capfd at the same time" -def pytest_funcarg__capsys(request): +@pytest.fixture +def capsys(request): """enables capturing of writes to sys.stdout/sys.stderr and makes captured output available via ``capsys.readouterr()`` method calls which return a ``(out, err)`` tuple. @@ -242,7 +220,8 @@ def pytest_funcarg__capsys(request): request.node._capfuncarg = c = CaptureFixture(SysCapture) return c -def pytest_funcarg__capfd(request): +@pytest.fixture +def capfd(request): """enables capturing of writes to file descriptors 1 and 2 and makes captured output available via ``capsys.readouterr()`` method calls which return a ``(out, err)`` tuple. diff --git a/testing/test_capture.py b/testing/test_capture.py index f346ca160..6274920de 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -541,8 +541,8 @@ def test_capture_conftest_runtest_setup(testdir): assert 'hello19' not in result.stdout.str() -@pytest.mark.xfail(sys.version_info>=(3,), reason='demonstrate #412') -def test_capture_badoutput(testdir): +@pytest.mark.xfail("sys.version_info >= (3,)") +def test_capture_badoutput_issue412(testdir): testdir.makepyfile(""" import os @@ -552,11 +552,12 @@ def test_capture_badoutput(testdir): assert 0 """) result = testdir.runpytest('--cap=fd') - #this fails on python3 - fnmatch first for debugging - result.stdout.fnmatch_lines([ - '*1 failed*', - ]) - assert result.ret == 1 + result.stdout.fnmatch_lines(''' + *def test_func* + *assert 0* + *Captured* + *1 failed* + ''') def test_capture_early_option_parsing(testdir): @@ -616,7 +617,7 @@ class TestTextIO: def test_bytes_io(): - f = capture.BytesIO() + f = py.io.BytesIO() f.write(tobytes("hello")) pytest.raises(TypeError, "f.write(totext('hello'))") s = f.getvalue()