diff options
| author | Senthil Kumaran <senthil@uthcode.com> | 2012-07-05 02:50:29 (GMT) | 
|---|---|---|
| committer | Senthil Kumaran <senthil@uthcode.com> | 2012-07-05 02:50:29 (GMT) | 
| commit | 3b30b19e0a7b9adb37a590d257438544ff0b032c (patch) | |
| tree | 0e0ca4c9c6e43832a4976ddb6a28092b54085d9a /Lib/test/test_cmd_line_script.py | |
| parent | d0f5f4827db59fb210adb1b50fd3a536ee7f20da (diff) | |
| download | cpython-3b30b19e0a7b9adb37a590d257438544ff0b032c.zip cpython-3b30b19e0a7b9adb37a590d257438544ff0b032c.tar.gz cpython-3b30b19e0a7b9adb37a590d257438544ff0b032c.tar.bz2  | |
Fix closes issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Diffstat (limited to 'Lib/test/test_cmd_line_script.py')
| -rw-r--r-- | Lib/test/test_cmd_line_script.py | 18 | 
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py index 099471f..8b05227 100644 --- a/Lib/test/test_cmd_line_script.py +++ b/Lib/test/test_cmd_line_script.py @@ -6,11 +6,14 @@ import os.path  import test.test_support  from test.script_helper import (run_python,                                  temp_dir, make_script, compile_script, -                                make_pkg, make_zip_script, make_zip_pkg) +                                assert_python_failure, make_pkg, +                                make_zip_script, make_zip_pkg)  verbose = test.test_support.verbose +example_args = ['test1', 'test2', 'test3'] +  test_source = """\  # Script may be run with optimisation enabled, so don't rely on assert  # statements being executed @@ -204,6 +207,19 @@ class CmdLineTest(unittest.TestCase):              launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')              self._check_import_error(launch_name, msg) +    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: +            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():      test.test_support.run_unittest(CmdLineTest)  | 
