]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-130660: Add a test for pdb when user quits after interact command (#130852)
authorTian Gao <gaogaotiantian@hotmail.com>
Tue, 4 Mar 2025 20:10:32 +0000 (15:10 -0500)
committerGitHub <noreply@github.com>
Tue, 4 Mar 2025 20:10:32 +0000 (15:10 -0500)
Lib/test/test_pdb.py

index 7ecb8d4cd4d5fa056026792fa60033f811cb4900..a3246e4ec76b5061d4e690e3b8a4928f28e67ee6 100644 (file)
@@ -4342,6 +4342,32 @@ class PdbTestInline(unittest.TestCase):
         # The quit prompt should be printed exactly twice
         self.assertEqual(stdout.count("Quit anyway"), 2)
 
+    def test_quit_after_interact(self):
+        """
+        interact command will set sys.ps1 temporarily, we need to make sure
+        that it's restored and pdb does not believe it's in interactive mode
+        after interact is done.
+        """
+        script = """
+            x = 1
+            breakpoint()
+        """
+
+        commands = """
+            interact
+            quit()
+            q
+            y
+        """
+
+        stdout, stderr = self._run_script(script, commands)
+        # Normal exit should not print anything to stderr
+        self.assertEqual(stderr, "")
+        # The quit prompt should be printed exactly once
+        self.assertEqual(stdout.count("Quit anyway"), 1)
+        # BdbQuit should not be printed
+        self.assertNotIn("BdbQuit", stdout)
+
     def test_set_trace_with_skip(self):
         """GH-82897
         Inline set_trace() should break unconditionally. This example is a