| 2152 | |
| 2153 | @force_not_colorized |
| 2154 | def test_proper_tracebacklimit(self): |
| 2155 | env = os.environ.copy() |
| 2156 | for set_tracebacklimit in [True, False]: |
| 2157 | commands = ("import sys\n" + |
| 2158 | ("sys.tracebacklimit = 1\n" if set_tracebacklimit else "") + |
| 2159 | "def x1(): 1/0\n\n" |
| 2160 | "def x2(): x1()\n\n" |
| 2161 | "def x3(): x2()\n\n" |
| 2162 | "x3()\n" |
| 2163 | "exit()\n") |
| 2164 | |
| 2165 | for basic_repl in [True, False]: |
| 2166 | if basic_repl: |
| 2167 | env["PYTHON_BASIC_REPL"] = "1" |
| 2168 | else: |
| 2169 | env.pop("PYTHON_BASIC_REPL", None) |
| 2170 | with self.subTest(set_tracebacklimit=set_tracebacklimit, |
| 2171 | basic_repl=basic_repl): |
| 2172 | output, exit_code = self.run_repl(commands, env=env, skip=True) |
| 2173 | self.assertIn("in x1", output) |
| 2174 | if set_tracebacklimit: |
| 2175 | self.assertNotIn("in x2", output) |
| 2176 | self.assertNotIn("in x3", output) |
| 2177 | self.assertNotIn("in <module>", output) |
| 2178 | else: |
| 2179 | self.assertIn("in x2", output) |
| 2180 | self.assertIn("in x3", output) |
| 2181 | self.assertIn("in <module>", output) |
| 2182 | |
| 2183 | def test_null_byte(self): |
| 2184 | output, exit_code = self.run_repl("\x00\nexit()\n") |