diff options
| author | CF Bolz-Tereick <cfbolz@gmx.de> | 2024-08-23 11:59:08 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-23 11:59:08 (GMT) |
| commit | 0955db1bd80edf8e20788b95dcfe8580aa0ade19 (patch) | |
| tree | 485812e0a0656f1b9d7998e46f052761c0e75147 /Lib/test/test_pyrepl/test_pyrepl.py | |
| parent | 95b4f9c9ad3d7a13442a6874bbcf3683d17723dc (diff) | |
| download | cpython-0955db1bd80edf8e20788b95dcfe8580aa0ade19.zip cpython-0955db1bd80edf8e20788b95dcfe8580aa0ade19.tar.gz cpython-0955db1bd80edf8e20788b95dcfe8580aa0ade19.tar.bz2 | |
[3.13] gh-82378 fix sys.tracebacklimit in pyrepl, approach 2 (GH-123062) (#123252)
Make sure that pyrepl uses the same logic for sys.tracebacklimit as both
the basic repl and the standard sys.excepthook
(cherry picked from commit 63603bca35798c166e1b8e0be76aef69217f8b1b)
Diffstat (limited to 'Lib/test/test_pyrepl/test_pyrepl.py')
| -rw-r--r-- | Lib/test/test_pyrepl/test_pyrepl.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py index 9944cd0..b03cf13 100644 --- a/Lib/test/test_pyrepl/test_pyrepl.py +++ b/Lib/test/test_pyrepl/test_pyrepl.py @@ -1020,7 +1020,7 @@ class TestMain(TestCase): env.update({"TERM": "dumb"}) output, exit_code = self.run_repl("exit()\n", env=env) self.assertEqual(exit_code, 0) - self.assertIn("warning: can\'t use pyrepl", output) + self.assertIn("warning: can't use pyrepl", output) self.assertNotIn("Exception", output) self.assertNotIn("Traceback", output) @@ -1114,6 +1114,38 @@ class TestMain(TestCase): self.assertIn("IndentationError: unexpected indent", output) self.assertIn("<python-input-0>", output) + @force_not_colorized + def test_proper_tracebacklimit(self): + env = os.environ.copy() + for set_tracebacklimit in [True, False]: + commands = ("import sys\n" + + ("sys.tracebacklimit = 1\n" if set_tracebacklimit else "") + + "def x1(): 1/0\n\n" + "def x2(): x1()\n\n" + "def x3(): x2()\n\n" + "x3()\n" + "exit()\n") + + for basic_repl in [True, False]: + if basic_repl: + env["PYTHON_BASIC_REPL"] = "1" + else: + env.pop("PYTHON_BASIC_REPL", None) + with self.subTest(set_tracebacklimit=set_tracebacklimit, + basic_repl=basic_repl): + output, exit_code = self.run_repl(commands, env=env) + if "can't use pyrepl" in output: + self.skipTest("pyrepl not available") + self.assertIn("in x1", output) + if set_tracebacklimit: + self.assertNotIn("in x2", output) + self.assertNotIn("in x3", output) + self.assertNotIn("in <module>", output) + else: + self.assertIn("in x2", output) + self.assertIn("in x3", output) + self.assertIn("in <module>", output) + def run_repl( self, repl_input: str | list[str], |
