From a81fd57d2e6e1404b9ae38189577361134591628 Mon Sep 17 00:00:00 2001 From: Olga Pustovalova <162949+olp-cs@users.noreply.github.com> Date: Sat, 19 Jul 2025 09:17:56 +0000 Subject: [PATCH 1/2] gh-136438: Make sure `test_remote_pdb` pass with all optimization levels --- Lib/test/test_remote_pdb.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Lib/test/test_remote_pdb.py b/Lib/test/test_remote_pdb.py index a1c50af15f3dd2..de89be3dd32136 100644 --- a/Lib/test/test_remote_pdb.py +++ b/Lib/test/test_remote_pdb.py @@ -279,6 +279,7 @@ def test_handling_other_message(self): expected_stdout="Some message.\n", ) + @unittest.skipIf(sys.flags.optimize >= 2, "Disabled for optimization -OO") def test_handling_help_for_command(self): """Test handling a request to display help for a command.""" incoming = [ @@ -290,6 +291,7 @@ def test_handling_help_for_command(self): expected_stdout_substring="Usage: ll | longlist", ) + @unittest.skipIf(sys.flags.optimize >= 2, "Disabled for optimization -OO") def test_handling_help_without_a_specific_topic(self): """Test handling a request to display a help overview.""" incoming = [ @@ -301,6 +303,7 @@ def test_handling_help_without_a_specific_topic(self): expected_stdout_substring="type help ", ) + @unittest.skipIf(sys.flags.optimize >= 2, "Help not available for -OO") def test_handling_help_pdb(self): """Test handling a request to display the full PDB manual.""" incoming = [ @@ -312,6 +315,18 @@ def test_handling_help_pdb(self): expected_stdout_substring=">>> import pdb", ) + @unittest.skipIf(sys.flags.optimize < 2, "Needs -OO") + def test_handling_no_help_available(self): + """Test handling a request when no help if available.""" + incoming = [ + ("server", {"help": "pdb"}), + ] + self.do_test( + incoming=incoming, + expected_outgoing=[], + expected_stdout_substring="No help for 'pdb'", + ) + def test_handling_pdb_prompts(self): """Test responding to pdb's normal prompts.""" incoming = [ From 7b1aa3bf6659459cba7bc8194acf3db157537b90 Mon Sep 17 00:00:00 2001 From: Olga Pustovalova <162949+olp-cs@users.noreply.github.com> Date: Sat, 19 Jul 2025 10:28:34 +0000 Subject: [PATCH 2/2] Refactor test cases with @subTests; add test cases for the scenario when help is not available --- Lib/test/test_remote_pdb.py | 64 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/Lib/test/test_remote_pdb.py b/Lib/test/test_remote_pdb.py index de89be3dd32136..280e2444ef7d34 100644 --- a/Lib/test/test_remote_pdb.py +++ b/Lib/test/test_remote_pdb.py @@ -11,7 +11,7 @@ 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,52 +279,50 @@ def test_handling_other_message(self): expected_stdout="Some message.\n", ) - @unittest.skipIf(sys.flags.optimize >= 2, "Disabled for optimization -OO") - def test_handling_help_for_command(self): - """Test handling a request to display help for a command.""" - incoming = [ - ("server", {"help": "ll"}), - ] - self.do_test( - incoming=incoming, - expected_outgoing=[], - expected_stdout_substring="Usage: ll | longlist", - ) - - @unittest.skipIf(sys.flags.optimize >= 2, "Disabled for optimization -OO") - def test_handling_help_without_a_specific_topic(self): - """Test handling a request to display a help overview.""" - incoming = [ - ("server", {"help": ""}), - ] - self.do_test( - incoming=incoming, - expected_outgoing=[], - expected_stdout_substring="type help ", - ) - @unittest.skipIf(sys.flags.optimize >= 2, "Help not available for -OO") - def test_handling_help_pdb(self): - """Test handling a request to display the full PDB manual.""" + @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 "), + # 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": "pdb"}), + ("server", help_request), ] self.do_test( incoming=incoming, expected_outgoing=[], - expected_stdout_substring=">>> import pdb", + expected_stdout_substring=expected_substring, ) @unittest.skipIf(sys.flags.optimize < 2, "Needs -OO") - def test_handling_no_help_available(self): - """Test handling a request when no help if available.""" + @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": "pdb"}), + ("server", help_request), ] self.do_test( incoming=incoming, expected_outgoing=[], - expected_stdout_substring="No help for 'pdb'", + expected_stdout_substring=expected_substring, ) def test_handling_pdb_prompts(self):