From 68786a6434d554505d28402fd322370645f5cdba Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 21 Nov 2012 20:43:31 +0100 Subject: [PATCH] fix bug where using capsys with pytest.set_trace() in a test function would break when looking at capsys.readouterr() --- CHANGELOG | 3 +++ _pytest/__init__.py | 2 +- _pytest/capture.py | 7 +++++-- setup.py | 2 +- testing/test_pdb.py | 16 ++++++++++++++++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5bc829593..c9ce69a8b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 ----------------------------------- diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 90400bc5d..345fe83a4 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.4.5dev1' +__version__ = '2.4.5dev2' diff --git a/_pytest/capture.py b/_pytest/capture.py index 3c8d77da6..71af4b348 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -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() diff --git a/setup.py b/setup.py index cacaa6be4..8a1867f9b 100644 --- a/setup.py +++ b/setup.py @@ -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'], diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 99903c035..71781afb4 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -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