Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f01a337

Browse files
committed
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
1 parent 035997f commit f01a337

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/test/test_cmd_line_script.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,21 @@ def test_issue8202_dash_m_file_ignored(self):
279279
self._check_output(script_name, rc, out,
280280
script_name, script_name, '', '')
281281

282+
def test_dash_m_error_code_is_one(self):
283+
# If a module is invoked with the -m command line flag
284+
# and results in an error that the return code to the
285+
# shell is '1'
286+
with temp_dir() as script_dir:
287+
with support.temp_cwd(path=script_dir):
288+
pkg_dir = os.path.join(script_dir, 'test_pkg')
289+
make_pkg(pkg_dir)
290+
script_name = _make_test_script(pkg_dir, 'other',
291+
"if __name__ == '__main__': raise ValueError")
292+
rc, out, err = assert_python_failure('-m', 'test_pkg.other', *example_args)
293+
if verbose > 1:
294+
print(out)
295+
self.assertEqual(rc, 1)
296+
282297
def test_main():
283298
support.run_unittest(CmdLineTest)
284299
support.reap_children()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #15033: Fix the exit status bug when modules invoked using -m swith,
14+
return the proper failure return value (1). Patch contributed by Jeff Knupp.
15+
1316
- Issue #12268: File readline, readlines and read() or readall() methods
1417
no longer lose data when an underlying read system call is interrupted.
1518
IOError is no longer raised due to a read system call returning EINTR

Modules/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ Py_Main(int argc, wchar_t **argv)
673673
sts = run_command(command, &cf);
674674
free(command);
675675
} else if (module) {
676-
sts = RunModule(module, 1);
676+
sts = (RunModule(module, 1) != 0);
677677
}
678678
else {
679679

0 commit comments

Comments
 (0)