11
11
import textwrap
12
12
import linecache
13
13
14
- from contextlib import ExitStack
14
+ from contextlib import ExitStack , redirect_stdout
15
15
from io import StringIO
16
16
from test .support import os_helper
17
17
# This little helper class is essential for testing pdb under doctest.
@@ -1688,7 +1688,7 @@ def test_module_without_a_main(self):
1688
1688
os_helper .rmtree (module_name )
1689
1689
init_file = module_name + '/__init__.py'
1690
1690
os .mkdir (module_name )
1691
- with open (init_file , 'w' ) as f :
1691
+ with open (init_file , 'w' ):
1692
1692
pass
1693
1693
self .addCleanup (os_helper .rmtree , module_name )
1694
1694
stdout , stderr = self ._run_pdb (['-m' , module_name ], "" )
@@ -1701,7 +1701,7 @@ def test_package_without_a_main(self):
1701
1701
os_helper .rmtree (pkg_name )
1702
1702
modpath = pkg_name + '/' + module_name
1703
1703
os .makedirs (modpath )
1704
- with open (modpath + '/__init__.py' , 'w' ) as f :
1704
+ with open (modpath + '/__init__.py' , 'w' ):
1705
1705
pass
1706
1706
self .addCleanup (os_helper .rmtree , pkg_name )
1707
1707
stdout , stderr = self ._run_pdb (['-m' , modpath .replace ('/' , '.' )], "" )
@@ -1915,19 +1915,20 @@ def test_checkline_after_reset(self):
1915
1915
self .assertEqual (db .checkline (os_helper .TESTFN , 1 ), 1 )
1916
1916
1917
1917
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 '''
1924
1923
1925
- """ )
1924
+ """ )
1925
+ with open (os_helper .TESTFN , "w" ) as f :
1926
1926
f .write (s )
1927
- db = pdb .Pdb ()
1928
1927
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 ))
1931
1932
1932
1933
1933
1934
def load_tests (* args ):
0 commit comments