mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-34783: Add test_cmd_line_script.test_nonexisting_script() (GH-9535)
Make sure that "./python script.py" does not crash if the script file doesn't exist.
This commit is contained in:
		
							parent
							
								
									1b77f929f8
								
							
						
					
					
						commit
						a46467ff19
					
				
					 1 changed files with 19 additions and 0 deletions
				
			
		|  | @ -630,6 +630,25 @@ def test_consistent_sys_path_for_module_execution(self): | |||
|             traceback_lines = stderr.decode().splitlines() | ||||
|             self.assertIn("No module named script_pkg", traceback_lines[-1]) | ||||
| 
 | ||||
|     def test_nonexisting_script(self): | ||||
|         # bpo-34783: "./python script.py" must not crash | ||||
|         # if the script file doesn't exist. | ||||
|         script = 'nonexistingscript.py' | ||||
|         self.assertFalse(os.path.exists(script)) | ||||
|         # Only test the base name, since the error message can use | ||||
|         # a relative path, whereas sys.executable can be an asolution path. | ||||
|         program = os.path.basename(sys.executable) | ||||
| 
 | ||||
|         proc = spawn_python(script, text=True, | ||||
|                             stdout=subprocess.PIPE, | ||||
|                             stderr=subprocess.PIPE) | ||||
|         out, err = proc.communicate() | ||||
|         # "./python" must be in the error message: | ||||
|         # "./python: can't open file (...)" | ||||
|         self.assertIn(program, err) | ||||
|         self.assertNotEqual(proc.returncode, 0) | ||||
| 
 | ||||
| 
 | ||||
| def test_main(): | ||||
|     support.run_unittest(CmdLineTest) | ||||
|     support.reap_children() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner