File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -630,6 +630,25 @@ def test_consistent_sys_path_for_module_execution(self):
630630 traceback_lines = stderr .decode ().splitlines ()
631631 self .assertIn ("No module named script_pkg" , traceback_lines [- 1 ])
632632
633+ def test_nonexisting_script (self ):
634+ # bpo-34783: "./python script.py" must not crash
635+ # if the script file doesn't exist.
636+ script = 'nonexistingscript.py'
637+ self .assertFalse (os .path .exists (script ))
638+ # Only test the base name, since the error message can use
639+ # a relative path, whereas sys.executable can be an asolution path.
640+ program = os .path .basename (sys .executable )
641+
642+ proc = spawn_python (script , text = True ,
643+ stdout = subprocess .PIPE ,
644+ stderr = subprocess .PIPE )
645+ out , err = proc .communicate ()
646+ # "./python" must be in the error message:
647+ # "./python: can't open file (...)"
648+ self .assertIn (program , err )
649+ self .assertNotEqual (proc .returncode , 0 )
650+
651+
633652def test_main ():
634653 support .run_unittest (CmdLineTest )
635654 support .reap_children ()
You can’t perform that action at this time.
0 commit comments