diff options
author | Tian Gao <gaogaotiantian@hotmail.com> | 2023-11-10 13:13:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 21:13:29 +0000 |
commit | 148af38cd0adc1c2dde3c937ebbda4ee60b27b33 (patch) | |
tree | 83b6f242e0671d5fa7fcfc6ac970170a52128ad2 /Lib/test/test_cmd.py | |
parent | afac3c9b7eace4a3e503e93bb76eda32d8217ad7 (diff) | |
download | cpython-148af38cd0adc1c2dde3c937ebbda4ee60b27b33.tar.gz cpython-148af38cd0adc1c2dde3c937ebbda4ee60b27b33.zip |
gh-80731: Avoid executing code in except block in cmd (GH-111740)
Diffstat (limited to 'Lib/test/test_cmd.py')
-rw-r--r-- | Lib/test/test_cmd.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_cmd.py b/Lib/test/test_cmd.py index 28f80766677..951336fa085 100644 --- a/Lib/test/test_cmd.py +++ b/Lib/test/test_cmd.py @@ -244,6 +244,21 @@ class TestAlternateInput(unittest.TestCase): "(Cmd) *** Unknown syntax: EOF\n")) +class CmdPrintExceptionClass(cmd.Cmd): + """ + GH-80731 + cmd.Cmd should print the correct exception in default() + >>> mycmd = CmdPrintExceptionClass() + >>> try: + ... raise ValueError("test") + ... except ValueError: + ... mycmd.onecmd("not important") + (<class 'ValueError'>, ValueError('test')) + """ + + def default(self, line): + print(sys.exc_info()[:2]) + def load_tests(loader, tests, pattern): tests.addTest(doctest.DocTestSuite()) return tests |