From e2bb81124c17b92710fdcee3424dde538bcb7622 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 22 Jan 2014 19:48:10 +0100 Subject: [PATCH] simplify StdCaptureFD snapshot reading --- _pytest/capture.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/_pytest/capture.py b/_pytest/capture.py index 1d158ef72..2907bab05 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -538,17 +538,16 @@ class StdCaptureFD(Capture): def readouterr(self): """ return snapshot value of stdout/stderr capturings. """ - if hasattr(self, "out"): - out = self._readsnapshot(self.out.tmpfile) - else: - out = "" - if hasattr(self, "err"): - err = self._readsnapshot(self.err.tmpfile) - else: - err = "" - return [out, err] + out = self._readsnapshot('out') + err = self._readsnapshot('err') + return out, err + + def _readsnapshot(self, name): + if hasattr(self, name): + f = getattr(self, name).tmpfile + else: + return '' - def _readsnapshot(self, f): f.seek(0) res = f.read() enc = getattr(f, "encoding", None)