@@ -2603,12 +2603,12 @@ def _run_pdb(self, pdb_args, commands,
26032603 cmd ,
26042604 stdout = subprocess .PIPE ,
26052605 stdin = subprocess .PIPE ,
2606- stderr = subprocess .STDOUT ,
2606+ stderr = subprocess .PIPE ,
26072607 env = {** env , 'PYTHONIOENCODING' : 'utf-8' }
26082608 ) as proc :
26092609 stdout , stderr = proc .communicate (str .encode (commands ))
2610- stdout = stdout and bytes .decode (stdout )
2611- stderr = stderr and bytes .decode (stderr )
2610+ stdout = bytes .decode (stdout ) if isinstance ( stdout , bytes ) else stdout
2611+ stderr = bytes .decode (stderr ) if isinstance ( stderr , bytes ) else stderr
26122612 self .assertEqual (
26132613 proc .returncode ,
26142614 expected_returncode ,
@@ -2756,7 +2756,7 @@ def test_issue7964(self):
27562756 proc = subprocess .Popen (cmd ,
27572757 stdout = subprocess .PIPE ,
27582758 stdin = subprocess .PIPE ,
2759- stderr = subprocess .STDOUT ,
2759+ stderr = subprocess .PIPE ,
27602760 )
27612761 self .addCleanup (proc .stdout .close )
27622762 stdout , stderr = proc .communicate (b'quit\n ' )
@@ -2840,7 +2840,7 @@ def start_pdb():
28402840 proc = subprocess .Popen (cmd ,
28412841 stdout = subprocess .PIPE ,
28422842 stdin = subprocess .PIPE ,
2843- stderr = subprocess .STDOUT ,
2843+ stderr = subprocess .PIPE ,
28442844 env = {** os .environ , 'PYTHONIOENCODING' : 'utf-8' }
28452845 )
28462846 self .addCleanup (proc .stdout .close )
@@ -2870,7 +2870,7 @@ def start_pdb():
28702870 proc = subprocess .Popen (cmd ,
28712871 stdout = subprocess .PIPE ,
28722872 stdin = subprocess .PIPE ,
2873- stderr = subprocess .STDOUT ,
2873+ stderr = subprocess .PIPE ,
28742874 env = {** os .environ , 'PYTHONIOENCODING' : 'utf-8' }
28752875 )
28762876 self .addCleanup (proc .stdout .close )
@@ -2886,10 +2886,10 @@ def test_issue16180(self):
28862886 stdout , stderr = self .run_pdb_script (
28872887 script , commands
28882888 )
2889- self .assertIn (expected , stdout ,
2889+ self .assertIn (expected , stderr ,
28902890 '\n \n Expected:\n {}\n Got:\n {}\n '
28912891 'Fail to handle a syntax error in the debuggee.'
2892- .format (expected , stdout ))
2892+ .format (expected , stderr ))
28932893
28942894 def test_issue84583 (self ):
28952895 # A syntax error from ast.literal_eval should not make pdb exit.
@@ -2900,11 +2900,12 @@ def test_issue84583(self):
29002900 quit
29012901 """
29022902 stdout , stderr = self .run_pdb_script (script , commands )
2903- # The code should appear 3 times in the stdout:
2904- # 1. when pdb starts
2905- # 2. when the exception is raised, in trackback
2906- # 3. in where command
2907- self .assertEqual (stdout .count ("ast.literal_eval('')" ), 3 )
2903+ # The code should appear 3 times in the stdout/stderr:
2904+ # 1. when pdb starts (stdout)
2905+ # 2. when the exception is raised, in trackback (stderr)
2906+ # 3. in where command (stdout)
2907+ self .assertEqual (stdout .count ("ast.literal_eval('')" ), 2 )
2908+ self .assertEqual (stderr .count ("ast.literal_eval('')" ), 1 )
29082909
29092910 def test_issue26053 (self ):
29102911 # run command of pdb prompt echoes the correct args
@@ -3133,9 +3134,9 @@ def test_dir_as_script(self):
31333134
31343135 def test_invalid_cmd_line_options (self ):
31353136 stdout , stderr = self ._run_pdb (["-c" ], "" , expected_returncode = 2 )
3136- self .assertIn (f"pdb: error: argument -c/--command: expected one argument" , stdout .split ('\n ' )[1 ])
3137+ self .assertIn (f"pdb: error: argument -c/--command: expected one argument" , stderr .split ('\n ' )[1 ])
31373138 stdout , stderr = self ._run_pdb (["--spam" , "-m" , "pdb" ], "" , expected_returncode = 2 )
3138- self .assertIn (f"pdb: error: unrecognized arguments: --spam" , stdout .split ('\n ' )[1 ])
3139+ self .assertIn (f"pdb: error: unrecognized arguments: --spam" , stderr .split ('\n ' )[1 ])
31393140
31403141 def test_blocks_at_first_code_line (self ):
31413142 script = """
@@ -3190,7 +3191,7 @@ def test_file_modified_after_execution_with_multiple_instances(self):
31903191 cmd ,
31913192 stdout = subprocess .PIPE ,
31923193 stdin = subprocess .PIPE ,
3193- stderr = subprocess .STDOUT ,
3194+ stderr = subprocess .PIPE ,
31943195 env = {** os .environ , 'PYTHONIOENCODING' : 'utf-8' },
31953196 ) as proc :
31963197 stdout , _ = proc .communicate (str .encode (commands ))
0 commit comments