fix bug where using capsys with pytest.set_trace() in a test

function would break when looking at capsys.readouterr()
This commit is contained in:
holger krekel 2012-11-21 20:43:31 +01:00
parent b97de57ebe
commit 68786a6434
5 changed files with 26 additions and 4 deletions

View File

@ -7,6 +7,9 @@ Changes between 2.3.4 and 2.3.5dev
- improve docstring for metafunc.parametrize()
- fix bug where using capsys with pytest.set_trace() in a test
function would break when looking at capsys.readouterr()
Changes between 2.3.3 and 2.3.4
-----------------------------------

View File

@ -1,2 +1,2 @@
#
__version__ = '2.4.5dev1'
__version__ = '2.4.5dev2'

View File

@ -211,12 +211,15 @@ class CaptureFixture:
def _finalize(self):
if hasattr(self, 'capture'):
outerr = self.capture.reset()
outerr = self._outerr = self.capture.reset()
del self.capture
return outerr
def readouterr(self):
return self.capture.readouterr()
try:
return self.capture.readouterr()
except AttributeError:
return self._outerr
def close(self):
self._finalize()

View File

@ -12,7 +12,7 @@ def main():
name='pytest',
description='py.test: simple powerful testing with Python',
long_description = long_description,
version='2.4.5dev1',
version='2.4.5dev2',
url='http://pytest.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

View File

@ -106,6 +106,22 @@ class TestPDB:
if child.isalive():
child.wait()
def test_pdb_and_capsys(self, testdir):
p1 = testdir.makepyfile("""
import pytest
def test_1(capsys):
print ("hello1")
pytest.set_trace()
""")
child = testdir.spawn_pytest(str(p1))
child.expect("test_1")
child.send("capsys.readouterr()\n")
child.expect("hello1")
child.sendeof()
rest = child.read()
if child.isalive():
child.wait()
def test_pdb_interaction_doctest(self, testdir):
p1 = testdir.makepyfile("""
import pytest