From e0b584d0485329bad3b881c0c7a4e040f4b0b6dd Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 23 May 2019 08:56:52 +0200 Subject: [PATCH] CaptureFixture: do not crash in _suspend when not started This happened in test_pdb_with_caplog_on_pdb_invocation. --- src/_pytest/capture.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 560171134..84f773254 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -358,8 +358,7 @@ class CaptureFixture(object): self._captured_err = self.captureclass.EMPTY_BUFFER def _start(self): - # Start if not started yet - if getattr(self, "_capture", None) is None: + if self._capture is None: self._capture = MultiCapture( out=True, err=True, in_=False, Capture=self.captureclass ) @@ -389,11 +388,13 @@ class CaptureFixture(object): def _suspend(self): """Suspends this fixture's own capturing temporarily.""" - self._capture.suspend_capturing() + if self._capture is not None: + self._capture.suspend_capturing() def _resume(self): """Resumes this fixture's own capturing temporarily.""" - self._capture.resume_capturing() + if self._capture is not None: + self._capture.resume_capturing() @contextlib.contextmanager def disabled(self):