@@ -46,13 +46,7 @@ def pytest_load_initial_conftests(early_config, parser, args, __multicall__):
46
46
pluginmanager .register (capman , "capturemanager" )
47
47
48
48
# make sure that capturemanager is properly reset at final shutdown
49
- def teardown ():
50
- try :
51
- capman .reset_capturings ()
52
- except ValueError :
53
- pass
54
-
55
- pluginmanager .add_shutdown (teardown )
49
+ pluginmanager .add_shutdown (capman .reset_capturings )
56
50
57
51
# make sure logging does not raise exceptions at the end
58
52
def silence_logging_at_shutdown ():
@@ -124,16 +118,18 @@ def resumecapture(self, method=None):
124
118
self ._method2capture [method ] = cap = self ._getcapture (method )
125
119
cap .start_capturing ()
126
120
else :
127
- cap .pop_outerr_to_orig ()
121
+ cap .resume_capturing ()
128
122
129
123
def suspendcapture (self , item = None ):
130
124
self .deactivate_funcargs ()
131
125
method = self .__dict__ .pop ("_capturing" , None )
126
+ outerr = "" , ""
132
127
if method is not None :
133
128
cap = self ._method2capture .get (method )
134
129
if cap is not None :
135
- return cap .readouterr ()
136
- return "" , ""
130
+ outerr = cap .readouterr ()
131
+ cap .suspend_capturing ()
132
+ return outerr
137
133
138
134
def activate_funcargs (self , pyfuncitem ):
139
135
capfuncarg = pyfuncitem .__dict__ .pop ("_capfuncarg" , None )
@@ -316,6 +312,18 @@ def pop_outerr_to_orig(self):
316
312
if err :
317
313
self .err .writeorg (err )
318
314
315
+ def suspend_capturing (self ):
316
+ if self .out :
317
+ self .out .suspend ()
318
+ if self .err :
319
+ self .err .suspend ()
320
+
321
+ def resume_capturing (self ):
322
+ if self .out :
323
+ self .out .resume ()
324
+ if self .err :
325
+ self .err .resume ()
326
+
319
327
def stop_capturing (self ):
320
328
""" stop capturing and reset capturing streams """
321
329
if hasattr (self , '_reset' ):
@@ -334,7 +342,7 @@ def readouterr(self):
334
342
self .err .snap () if self .err is not None else "" )
335
343
336
344
class NoCapture :
337
- __init__ = start = done = lambda * args : None
345
+ __init__ = start = done = suspend = resume = lambda * args : None
338
346
339
347
class FDCapture :
340
348
""" Capture IO to/from a given os-level filedescriptor. """
0 commit comments