@@ -2603,12 +2603,12 @@ def _run_pdb(self, pdb_args, commands,
2603
2603
cmd ,
2604
2604
stdout = subprocess .PIPE ,
2605
2605
stdin = subprocess .PIPE ,
2606
- stderr = subprocess .STDOUT ,
2606
+ stderr = subprocess .PIPE ,
2607
2607
env = {** env , 'PYTHONIOENCODING' : 'utf-8' }
2608
2608
) as proc :
2609
2609
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
2612
2612
self .assertEqual (
2613
2613
proc .returncode ,
2614
2614
expected_returncode ,
@@ -2756,7 +2756,7 @@ def test_issue7964(self):
2756
2756
proc = subprocess .Popen (cmd ,
2757
2757
stdout = subprocess .PIPE ,
2758
2758
stdin = subprocess .PIPE ,
2759
- stderr = subprocess .STDOUT ,
2759
+ stderr = subprocess .PIPE ,
2760
2760
)
2761
2761
self .addCleanup (proc .stdout .close )
2762
2762
stdout , stderr = proc .communicate (b'quit\n ' )
@@ -2840,7 +2840,7 @@ def start_pdb():
2840
2840
proc = subprocess .Popen (cmd ,
2841
2841
stdout = subprocess .PIPE ,
2842
2842
stdin = subprocess .PIPE ,
2843
- stderr = subprocess .STDOUT ,
2843
+ stderr = subprocess .PIPE ,
2844
2844
env = {** os .environ , 'PYTHONIOENCODING' : 'utf-8' }
2845
2845
)
2846
2846
self .addCleanup (proc .stdout .close )
@@ -2870,7 +2870,7 @@ def start_pdb():
2870
2870
proc = subprocess .Popen (cmd ,
2871
2871
stdout = subprocess .PIPE ,
2872
2872
stdin = subprocess .PIPE ,
2873
- stderr = subprocess .STDOUT ,
2873
+ stderr = subprocess .PIPE ,
2874
2874
env = {** os .environ , 'PYTHONIOENCODING' : 'utf-8' }
2875
2875
)
2876
2876
self .addCleanup (proc .stdout .close )
@@ -2886,10 +2886,10 @@ def test_issue16180(self):
2886
2886
stdout , stderr = self .run_pdb_script (
2887
2887
script , commands
2888
2888
)
2889
- self .assertIn (expected , stdout ,
2889
+ self .assertIn (expected , stderr ,
2890
2890
'\n \n Expected:\n {}\n Got:\n {}\n '
2891
2891
'Fail to handle a syntax error in the debuggee.'
2892
- .format (expected , stdout ))
2892
+ .format (expected , stderr ))
2893
2893
2894
2894
def test_issue84583 (self ):
2895
2895
# A syntax error from ast.literal_eval should not make pdb exit.
@@ -2900,11 +2900,12 @@ def test_issue84583(self):
2900
2900
quit
2901
2901
"""
2902
2902
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 )
2908
2909
2909
2910
def test_issue26053 (self ):
2910
2911
# run command of pdb prompt echoes the correct args
@@ -3133,9 +3134,9 @@ def test_dir_as_script(self):
3133
3134
3134
3135
def test_invalid_cmd_line_options (self ):
3135
3136
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 ])
3137
3138
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 ])
3139
3140
3140
3141
def test_blocks_at_first_code_line (self ):
3141
3142
script = """
@@ -3190,7 +3191,7 @@ def test_file_modified_after_execution_with_multiple_instances(self):
3190
3191
cmd ,
3191
3192
stdout = subprocess .PIPE ,
3192
3193
stdin = subprocess .PIPE ,
3193
- stderr = subprocess .STDOUT ,
3194
+ stderr = subprocess .PIPE ,
3194
3195
env = {** os .environ , 'PYTHONIOENCODING' : 'utf-8' },
3195
3196
) as proc :
3196
3197
stdout , _ = proc .communicate (str .encode (commands ))
0 commit comments