Skip to content

Commit 0e4f913

Browse files
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 e08e491) Co-authored-by: Victor Stinner <[email protected]>
1 parent a5bc0ff commit 0e4f913

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

Lib/test/test_pdb.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import textwrap
1212
import linecache
1313

14-
from contextlib import ExitStack
14+
from contextlib import ExitStack, redirect_stdout
1515
from io import StringIO
1616
from test.support import os_helper
1717
# This little helper class is essential for testing pdb under doctest.
@@ -1688,7 +1688,7 @@ def test_module_without_a_main(self):
16881688
os_helper.rmtree(module_name)
16891689
init_file = module_name + '/__init__.py'
16901690
os.mkdir(module_name)
1691-
with open(init_file, 'w') as f:
1691+
with open(init_file, 'w'):
16921692
pass
16931693
self.addCleanup(os_helper.rmtree, module_name)
16941694
stdout, stderr = self._run_pdb(['-m', module_name], "")
@@ -1701,7 +1701,7 @@ def test_package_without_a_main(self):
17011701
os_helper.rmtree(pkg_name)
17021702
modpath = pkg_name + '/' + module_name
17031703
os.makedirs(modpath)
1704-
with open(modpath + '/__init__.py', 'w') as f:
1704+
with open(modpath + '/__init__.py', 'w'):
17051705
pass
17061706
self.addCleanup(os_helper.rmtree, pkg_name)
17071707
stdout, stderr = self._run_pdb(['-m', modpath.replace('/', '.')], "")
@@ -1915,19 +1915,20 @@ def test_checkline_after_reset(self):
19151915
self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1)
19161916

19171917
def test_checkline_is_not_executable(self):
1918-
with open(os_helper.TESTFN, "w") as f:
1919-
# Test for comments, docstrings and empty lines
1920-
s = textwrap.dedent("""
1921-
# Comment
1922-
\"\"\" docstring \"\"\"
1923-
''' docstring '''
1918+
# Test for comments, docstrings and empty lines
1919+
s = textwrap.dedent("""
1920+
# Comment
1921+
\"\"\" docstring \"\"\"
1922+
''' docstring '''
19241923
1925-
""")
1924+
""")
1925+
with open(os_helper.TESTFN, "w") as f:
19261926
f.write(s)
1927-
db = pdb.Pdb()
19281927
num_lines = len(s.splitlines()) + 2 # Test for EOF
1929-
for lineno in range(num_lines):
1930-
self.assertFalse(db.checkline(os_helper.TESTFN, lineno))
1928+
with redirect_stdout(StringIO()):
1929+
db = pdb.Pdb()
1930+
for lineno in range(num_lines):
1931+
self.assertFalse(db.checkline(os_helper.TESTFN, lineno))
19311932

19321933

19331934
def load_tests(*args):

0 commit comments

Comments
 (0)