@@ -543,6 +543,12 @@ def input_transformers_cleanup(self):
543543 help = "Warn if running in a virtual environment with no IPython installed (so IPython from the global environment is used)." ,
544544 ).tag (config = True )
545545
546+ # Flag to disable the custom CapturingTee mechanism.
547+ # Useful in test environments to use the standard capturing of stdout/stderr.
548+ disable_capturing_tee = Bool (
549+ False , help = "Disable the custom CapturingTee output capturing"
550+ ).tag (config = True )
551+
546552 # TODO: this part of prompt management should be moved to the frontends.
547553 # Use custom TraitTypes that convert '0'->'' and '\\n'->'\n'
548554 separate_in = SeparateUnicode ('\n ' ).tag (config = True )
@@ -3040,15 +3046,20 @@ def run_cell(
30403046 result : :class:`ExecutionResult`
30413047 """
30423048 result = None
3043- tee_out = CapturingTee (self , channel = "stdout" )
3044- tee_err = CapturingTee (self , channel = "stderr" )
3049+ tee_out = None
3050+ tee_err = None
3051+ if not self .disable_capturing_tee :
3052+ tee_out = CapturingTee (self , channel = "stdout" )
3053+ tee_err = CapturingTee (self , channel = "stderr" )
30453054 try :
30463055 result = self ._run_cell (
30473056 raw_cell , store_history , silent , shell_futures , cell_id
30483057 )
30493058 finally :
3050- tee_out .close ()
3051- tee_err .close ()
3059+ if tee_out is not None :
3060+ tee_out .close ()
3061+ if tee_err is not None :
3062+ tee_err .close ()
30523063 self .events .trigger ('post_execute' )
30533064 if not silent :
30543065 self .events .trigger ('post_run_cell' , result )
0 commit comments