[Python-checkins] cpython (merge 3.2 -> default): Fix issue # 15033 - Return the proper exitcode for failure when modules are

senthil.kumaran python-checkins at python.org
Thu Jul 5 04:34:02 CEST 2012


http://hg.python.org/cpython/rev/1186d68715cc
changeset:   77947:1186d68715cc
parent:      77945:906c69928049
parent:      77946:fcbd3bda7c0f
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Wed Jul 04 19:33:45 2012 -0700
summary:
  Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp

files:
  Lib/test/test_cmd_line_script.py |  15 +++++++++++++++
  Misc/NEWS                        |   3 +++
  Modules/main.c                   |   2 +-
  3 files changed, 19 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -287,6 +287,21 @@
                     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_pep_409_verbiage(self):
         # Make sure PEP 409 syntax properly suppresses
         # the context of an exception
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 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 #15229: An OSError subclass whose __init__ doesn't call back
   OSError.__init__ could produce incomplete instances, leading to crashes
   when calling str() on them.
diff --git a/Modules/main.c b/Modules/main.c
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -660,7 +660,7 @@
         sts = run_command(command, &cf);
         free(command);
     } else if (module) {
-        sts = RunModule(module, 1);
+        sts = (RunModule(module, 1) != 0);
     }
     else {
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list