]> granicus.if.org Git - python/commitdiff
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked...
authorSenthil Kumaran <senthil@uthcode.com>
Thu, 5 Jul 2012 02:28:16 +0000 (19:28 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Thu, 5 Jul 2012 02:28:16 +0000 (19:28 -0700)
Lib/test/test_cmd_line_script.py
Misc/NEWS
Modules/main.c

index 77af347bb8f580617d1089edc70ae7e2f201b5d9..6b59d9634914834ee4fc64b6f3f4b53eafad72a8 100644 (file)
@@ -279,6 +279,21 @@ class CmdLineTest(unittest.TestCase):
                     self._check_output(script_name, rc, out,
                                       script_name, script_name, '', '')
 
+    def test_dash_m_error_code_is_one(self):
+        # If a module is invoked with the -m command line flag
+        # and results in an error that the return code to the
+        # shell is '1'
+        with temp_dir() as script_dir:
+            with support.temp_cwd(path=script_dir):
+                pkg_dir = os.path.join(script_dir, 'test_pkg')
+                make_pkg(pkg_dir)
+                script_name = _make_test_script(pkg_dir, 'other',
+                                                "if __name__ == '__main__': raise ValueError")
+                rc, out, err = assert_python_failure('-m', 'test_pkg.other', *example_args)
+                if verbose > 1:
+                    print(out)
+                self.assertEqual(rc, 1)
+
 def test_main():
     support.run_unittest(CmdLineTest)
     support.reap_children()
index 99515c0639227e32d2c07f77fd50909c6aa3bfec..5adf15e1d35af9d45016c0aa9a5d328ec4b6a27c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
 Core and Builtins
 -----------------
 
+- Issue #15033: Fix the exit status bug when modules invoked using -m swith,
+  return the proper failure return value (1). Patch contributed by Jeff Knupp.
+
 - Issue #12268: File readline, readlines and read() or readall() methods
   no longer lose data when an underlying read system call is interrupted.
   IOError is no longer raised due to a read system call returning EINTR
index 1282f4697be02a3c835896d52c7ff33f8df695be..5b4a7e2e64f18b0d5ae5d848f7349786067b888a 100644 (file)
@@ -673,7 +673,7 @@ Py_Main(int argc, wchar_t **argv)
         sts = run_command(command, &cf);
         free(command);
     } else if (module) {
-        sts = RunModule(module, 1);
+        sts = (RunModule(module, 1) != 0);
     }
     else {