]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-136438: Make sure `test_remote_pdb` pass with all optimization levels (GH-136788)
authorOlga Pustovalova <162949+olp-cs@users.noreply.github.com>
Sun, 20 Jul 2025 08:57:54 +0000 (10:57 +0200)
committerGitHub <noreply@github.com>
Sun, 20 Jul 2025 08:57:54 +0000 (10:57 +0200)
Lib/test/test_remote_pdb.py

index a1c50af15f3dd22f403898dd9d0646de9167e94f..280e2444ef7d34b2fd307bd95772b6a4d4a1cf79 100644 (file)
@@ -11,7 +11,7 @@ import textwrap
 import unittest
 import unittest.mock
 from contextlib import closing, contextmanager, redirect_stdout, redirect_stderr, ExitStack
-from test.support import is_wasi, cpython_only, force_color, requires_subprocess, SHORT_TIMEOUT
+from test.support import is_wasi, cpython_only, force_color, requires_subprocess, SHORT_TIMEOUT, subTests
 from test.support.os_helper import TESTFN, unlink
 from typing import List
 
@@ -279,37 +279,50 @@ class PdbClientTestCase(unittest.TestCase):
             expected_stdout="Some message.\n",
         )
 
-    def test_handling_help_for_command(self):
-        """Test handling a request to display help for a command."""
+    @unittest.skipIf(sys.flags.optimize >= 2, "Help not available for -OO")
+    @subTests(
+        "help_request,expected_substring",
+        [
+            # a request to display help for a command
+            ({"help": "ll"}, "Usage: ll | longlist"),
+            # a request to display a help overview
+            ({"help": ""}, "type help <topic>"),
+            # a request to display the full PDB manual
+            ({"help": "pdb"}, ">>> import pdb"),
+        ],
+    )
+    def test_handling_help_when_available(self, help_request, expected_substring):
+        """Test handling help requests when help is available."""
         incoming = [
-            ("server", {"help": "ll"}),
+            ("server", help_request),
         ]
         self.do_test(
             incoming=incoming,
             expected_outgoing=[],
-            expected_stdout_substring="Usage: ll | longlist",
+            expected_stdout_substring=expected_substring,
         )
 
-    def test_handling_help_without_a_specific_topic(self):
-        """Test handling a request to display a help overview."""
+    @unittest.skipIf(sys.flags.optimize < 2, "Needs -OO")
+    @subTests(
+        "help_request,expected_substring",
+        [
+            # a request to display help for a command
+            ({"help": "ll"}, "No help for 'll'"),
+            # a request to display a help overview
+            ({"help": ""}, "Undocumented commands"),
+            # a request to display the full PDB manual
+            ({"help": "pdb"}, "No help for 'pdb'"),
+        ],
+    )
+    def test_handling_help_when_not_available(self, help_request, expected_substring):
+        """Test handling help requests when help is not available."""
         incoming = [
-            ("server", {"help": ""}),
+            ("server", help_request),
         ]
         self.do_test(
             incoming=incoming,
             expected_outgoing=[],
-            expected_stdout_substring="type help <topic>",
-        )
-
-    def test_handling_help_pdb(self):
-        """Test handling a request to display the full PDB manual."""
-        incoming = [
-            ("server", {"help": "pdb"}),
-        ]
-        self.do_test(
-            incoming=incoming,
-            expected_outgoing=[],
-            expected_stdout_substring=">>> import pdb",
+            expected_stdout_substring=expected_substring,
         )
 
     def test_handling_pdb_prompts(self):