mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	bpo-34783: Fix test_nonexisting_script() (GH-9896)
Fix test_cmd_line_script.test_nonexisting_script(): the test must not rely on sys.executable, since main.c uses config->program which can be different than sys.executable in many cases (for example, on macOS when using the framework).
This commit is contained in:
		
							parent
							
								
									43a5bd7b45
								
							
						
					
					
						commit
						ea75187c68
					
				
					 1 changed files with 1 additions and 8 deletions
				
			
		|  | @ -630,8 +630,6 @@ def test_consistent_sys_path_for_module_execution(self): | |||
|             traceback_lines = stderr.decode().splitlines() | ||||
|             self.assertIn("No module named script_pkg", traceback_lines[-1]) | ||||
| 
 | ||||
|     @unittest.skipIf(sys.platform == 'darwin' and sys._framework, | ||||
|                         "test not valid for macOS framework builds") | ||||
|     def test_nonexisting_script(self): | ||||
|         # bpo-34783: "./python script.py" must not crash | ||||
|         # if the script file doesn't exist. | ||||
|  | @ -639,17 +637,12 @@ def test_nonexisting_script(self): | |||
|         #  is not the actual Python executable file name. | ||||
|         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.assertIn(": can't open file ", err) | ||||
|         self.assertNotEqual(proc.returncode, 0) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner