[Python-checkins] bpo-45208: Make test_pdb.test_checkline_is_not_executable() quiet (GH-28354) (GH-28363)

ambv webhook-mailer at python.org
Wed Sep 15 14:56:41 EDT 2021


https://github.com/python/cpython/commit/0e4f913da88791644150282e38ba21d1fca5fd91
commit: 0e4f913da88791644150282e38ba21d1fca5fd91
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-09-15T20:56:32+02:00
summary:

bpo-45208: Make test_pdb.test_checkline_is_not_executable() quiet (GH-28354) (GH-28363)

test_pdb.test_checkline_is_not_executable() no longer writes output
to stdout.

Remove also unused variables 'f'.
(cherry picked from commit e08e491a6ceea8ca105612df10147418c4e105b8)

Co-authored-by: Victor Stinner <vstinner at python.org>

files:
M Lib/test/test_pdb.py

diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index a9afca867ca8f..d4c037dabff97 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -11,7 +11,7 @@
 import textwrap
 import linecache
 
-from contextlib import ExitStack
+from contextlib import ExitStack, redirect_stdout
 from io import StringIO
 from test.support import os_helper
 # This little helper class is essential for testing pdb under doctest.
@@ -1688,7 +1688,7 @@ def test_module_without_a_main(self):
         os_helper.rmtree(module_name)
         init_file = module_name + '/__init__.py'
         os.mkdir(module_name)
-        with open(init_file, 'w') as f:
+        with open(init_file, 'w'):
             pass
         self.addCleanup(os_helper.rmtree, module_name)
         stdout, stderr = self._run_pdb(['-m', module_name], "")
@@ -1701,7 +1701,7 @@ def test_package_without_a_main(self):
         os_helper.rmtree(pkg_name)
         modpath = pkg_name + '/' + module_name
         os.makedirs(modpath)
-        with open(modpath + '/__init__.py', 'w') as f:
+        with open(modpath + '/__init__.py', 'w'):
             pass
         self.addCleanup(os_helper.rmtree, pkg_name)
         stdout, stderr = self._run_pdb(['-m', modpath.replace('/', '.')], "")
@@ -1915,19 +1915,20 @@ def test_checkline_after_reset(self):
         self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1)
 
     def test_checkline_is_not_executable(self):
-        with open(os_helper.TESTFN, "w") as f:
-            # Test for comments, docstrings and empty lines
-            s = textwrap.dedent("""
-                # Comment
-                \"\"\" docstring \"\"\"
-                ''' docstring '''
+        # Test for comments, docstrings and empty lines
+        s = textwrap.dedent("""
+            # Comment
+            \"\"\" docstring \"\"\"
+            ''' docstring '''
 
-            """)
+        """)
+        with open(os_helper.TESTFN, "w") as f:
             f.write(s)
-        db = pdb.Pdb()
         num_lines = len(s.splitlines()) + 2  # Test for EOF
-        for lineno in range(num_lines):
-            self.assertFalse(db.checkline(os_helper.TESTFN, lineno))
+        with redirect_stdout(StringIO()):
+            db = pdb.Pdb()
+            for lineno in range(num_lines):
+                self.assertFalse(db.checkline(os_helper.TESTFN, lineno))
 
 
 def load_tests(*args):



More information about the Python-checkins mailing list