summaryrefslogtreecommitdiff
path: root/tests/test_plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_plugin.py')
-rw-r--r--tests/test_plugin.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 132361a6..f7eb7e39 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -256,6 +256,10 @@ class PluggedApp(Plugin, cmd2.Cmd):
"""Repeat back the arguments"""
self.poutput(statement)
+ def do_skip_postcmd_hooks(self, _):
+ self.poutput("In do_skip_postcmd_hooks")
+ raise exceptions.SkipPostcommandHooks
+
parser = Cmd2ArgumentParser(description="Test parser")
parser.add_argument("my_arg", help="some help text")
@@ -847,6 +851,17 @@ def test_cmdfinalization_hook_exception(capsys):
assert err
assert app.called_cmdfinalization == 1
+def test_skip_postcmd_hooks(capsys):
+ app = PluggedApp()
+ app.register_postcmd_hook(app.postcmd_hook)
+ app.register_cmdfinalization_hook(app.cmdfinalization_hook)
+
+ # Cause a SkipPostcommandHooks exception and verify no postcmd stuff runs but cmdfinalization_hook still does
+ app.onecmd_plus_hooks('skip_postcmd_hooks')
+ out, err = capsys.readouterr()
+ assert "In do_skip_postcmd_hooks" in out
+ assert app.called_postcmd == 0
+ assert app.called_cmdfinalization == 1
def test_cmd2_argparse_exception(capsys):
"""