@@ -238,6 +238,14 @@ def cmdfinalization_hook_keyboard_interrupt(
238238 self .called_cmdfinalization += 1
239239 raise KeyboardInterrupt
240240
241+ def cmdfinalization_hook_passthrough_exception (
242+ self , data : cmd2 .plugin .CommandFinalizationData
243+ ) -> cmd2 .plugin .CommandFinalizationData :
244+ """A command finalization hook which raises a PassThroughException"""
245+ self .called_cmdfinalization += 1
246+ wrapped_ex = OSError ("Pass me up" )
247+ raise exceptions .PassThroughException (wrapped_ex = wrapped_ex )
248+
241249 def cmdfinalization_hook_not_enough_parameters (self ) -> plugin .CommandFinalizationData :
242250 """A command finalization hook with no parameters."""
243251 pass
@@ -916,15 +924,15 @@ def test_cmdfinalization_hook_exception(capsys):
916924 assert app .called_cmdfinalization == 1
917925
918926
919- def test_cmdfinalization_hook_system_exit (capsys ):
927+ def test_cmdfinalization_hook_system_exit ():
920928 app = PluggedApp ()
921929 app .register_cmdfinalization_hook (app .cmdfinalization_hook_system_exit )
922930 stop = app .onecmd_plus_hooks ('say hello' )
923931 assert stop
924932 assert app .called_cmdfinalization == 1
925933
926934
927- def test_cmdfinalization_hook_keyboard_interrupt (capsys ):
935+ def test_cmdfinalization_hook_keyboard_interrupt ():
928936 app = PluggedApp ()
929937 app .register_cmdfinalization_hook (app .cmdfinalization_hook_keyboard_interrupt )
930938
@@ -947,6 +955,16 @@ def test_cmdfinalization_hook_keyboard_interrupt(capsys):
947955 assert app .called_cmdfinalization == 1
948956
949957
958+ def test_cmdfinalization_hook_passthrough_exception ():
959+ app = PluggedApp ()
960+ app .register_cmdfinalization_hook (app .cmdfinalization_hook_passthrough_exception )
961+
962+ with pytest .raises (OSError ) as excinfo :
963+ app .onecmd_plus_hooks ('say hello' )
964+ assert 'Pass me up' in str (excinfo .value )
965+ assert app .called_cmdfinalization == 1
966+
967+
950968def test_skip_postcmd_hooks (capsys ):
951969 app = PluggedApp ()
952970 app .register_postcmd_hook (app .postcmd_hook )
0 commit comments