cleanup and refine issue412 test (still failing on py33)
This commit is contained in:
parent
b5467645d3
commit
923dcfd620
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue