4
4
"""
5
5
from __future__ import with_statement
6
6
7
+ import contextlib
7
8
import sys
8
9
import os
9
10
from tempfile import TemporaryFile
@@ -146,8 +147,8 @@ def pytest_keyboard_interrupt(self, excinfo):
146
147
def pytest_internalerror (self , excinfo ):
147
148
self .reset_capturings ()
148
149
149
- def suspendcapture_item (self , item , when ):
150
- out , err = self .suspendcapture ()
150
+ def suspendcapture_item (self , item , when , in_ = False ):
151
+ out , err = self .suspendcapture (in_ = in_ )
151
152
item .add_report_section (when , "stdout" , out )
152
153
item .add_report_section (when , "stderr" , err )
153
154
@@ -162,7 +163,7 @@ def capsys(request):
162
163
"""
163
164
if "capfd" in request ._funcargs :
164
165
raise request .raiseerror (error_capsysfderror )
165
- request .node ._capfuncarg = c = CaptureFixture (SysCapture )
166
+ request .node ._capfuncarg = c = CaptureFixture (SysCapture , request )
166
167
return c
167
168
168
169
@pytest .fixture
@@ -175,17 +176,18 @@ def capfd(request):
175
176
request .raiseerror (error_capsysfderror )
176
177
if not hasattr (os , 'dup' ):
177
178
pytest .skip ("capfd funcarg needs os.dup" )
178
- request .node ._capfuncarg = c = CaptureFixture (FDCapture )
179
+ request .node ._capfuncarg = c = CaptureFixture (FDCapture , request )
179
180
return c
180
181
181
182
182
183
class CaptureFixture :
183
- def __init__ (self , captureclass ):
184
+ def __init__ (self , captureclass , request ):
184
185
self .captureclass = captureclass
186
+ self .request = request
185
187
186
188
def _start (self ):
187
189
self ._capture = MultiCapture (out = True , err = True , in_ = False ,
188
- Capture = self .captureclass )
190
+ Capture = self .captureclass )
189
191
self ._capture .start_capturing ()
190
192
191
193
def close (self ):
@@ -200,6 +202,15 @@ def readouterr(self):
200
202
except AttributeError :
201
203
return self ._outerr
202
204
205
+ @contextlib .contextmanager
206
+ def disabled (self ):
207
+ capmanager = self .request .config .pluginmanager .getplugin ('capturemanager' )
208
+ capmanager .suspendcapture_item (self .request .node , "call" , in_ = True )
209
+ try :
210
+ yield
211
+ finally :
212
+ capmanager .resumecapture ()
213
+
203
214
204
215
def safe_text_dupfile (f , mode , default_encoding = "UTF8" ):
205
216
""" return a open text file object that's a duplicate of f on the
0 commit comments