Skip to content

Commit ea75187

Browse files
authored
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).
1 parent 43a5bd7 commit ea75187

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

Lib/test/test_cmd_line_script.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -630,26 +630,19 @@ 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-
@unittest.skipIf(sys.platform == 'darwin' and sys._framework,
634-
"test not valid for macOS framework builds")
635633
def test_nonexisting_script(self):
636634
# bpo-34783: "./python script.py" must not crash
637635
# if the script file doesn't exist.
638636
# (Skip test for macOS framework builds because sys.excutable name
639637
# is not the actual Python executable file name.
640638
script = 'nonexistingscript.py'
641639
self.assertFalse(os.path.exists(script))
642-
# Only test the base name, since the error message can use
643-
# a relative path, whereas sys.executable can be an asolution path.
644-
program = os.path.basename(sys.executable)
645640

646641
proc = spawn_python(script, text=True,
647642
stdout=subprocess.PIPE,
648643
stderr=subprocess.PIPE)
649644
out, err = proc.communicate()
650-
# "./python" must be in the error message:
651-
# "./python: can't open file (...)"
652-
self.assertIn(program, err)
645+
self.assertIn(": can't open file ", err)
653646
self.assertNotEqual(proc.returncode, 0)
654647

655648

0 commit comments

Comments
 (0)