diff -r 771f28686022 Lib/test/test_cmd_line.py --- a/Lib/test/test_cmd_line.py Thu Nov 22 23:56:51 2012 +0100 +++ b/Lib/test/test_cmd_line.py Fri Nov 23 17:38:59 2012 +0200 @@ -116,14 +116,22 @@ print >>script, "del sys.modules['__main__']" assert_python_ok(filename) - def test_unknown_options(self): + rc, out, err = assert_python_failure('-E', '-z') + self.assertIn(b'Unknown option', err) + self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1) + self.assertEqual(b'', out) # Add "without='-E'" to prevent _assert_python append env_vars -E # which changes the output of stderr rc, out, err = assert_python_failure('-z', without='-E') self.assertIn(b'Unknown option', err) self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1) self.assertEqual(b'', out) + rc, out, err = assert_python_failure('-a', '-z', without='-E') + self.assertIn(b'Unknown option', err) + self.assertEqual(err.splitlines().count(b'Unknown option: -a'), 1) + self.assertEqual(b'', out) + def test_main(): test.test_support.run_unittest(CmdLineTest) diff -r 771f28686022 Modules/main.c --- a/Modules/main.c Thu Nov 22 23:56:51 2012 +0100 +++ b/Modules/main.c Fri Nov 23 17:38:59 2012 +0200 @@ -264,6 +264,7 @@ /* Hash randomization needed early for all string operations (including -W and -X options). */ + _PyOS_opterr = 0; /* prevent printing the error in 1st pass */ while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { if (c == 'm' || c == 'c') { /* -c / -m is the last option: following arguments are diff -r 771f28686022 Python/getopt.c --- a/Python/getopt.c Thu Nov 22 23:56:51 2012 +0100 +++ b/Python/getopt.c Fri Nov 23 17:38:59 2012 +0200 @@ -41,7 +41,7 @@ void _PyOS_ResetGetOpt(void) { - _PyOS_opterr = 0; /* prevent printing the error in 2nd loop in main.c */ + _PyOS_opterr = 1; _PyOS_optind = 1; _PyOS_optarg = NULL; opt_ptr = "";