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

Skip to content

Commit f28fbab

Browse files
committed
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
2 parents 53089c6 + f01a337 commit f28fbab

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
@@ -287,6 +287,21 @@ def test_issue8202_dash_m_file_ignored(self):
287287
self._check_output(script_name, rc, out,
288288
script_name, script_name, '', '')
289289

290+
def test_dash_m_error_code_is_one(self):
291+
# If a module is invoked with the -m command line flag
292+
# and results in an error that the return code to the
293+
# shell is '1'
294+
with temp_dir() as script_dir:
295+
with support.temp_cwd(path=script_dir):
296+
pkg_dir = os.path.join(script_dir, 'test_pkg')
297+
make_pkg(pkg_dir)
298+
script_name = _make_test_script(pkg_dir, 'other',
299+
"if __name__ == '__main__': raise ValueError")
300+
rc, out, err = assert_python_failure('-m', 'test_pkg.other', *example_args)
301+
if verbose > 1:
302+
print(out)
303+
self.assertEqual(rc, 1)
304+
290305
def test_pep_409_verbiage(self):
291306
# Make sure PEP 409 syntax properly suppresses
292307
# the context of an exception

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.3.0 Beta 2?
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 #15229: An OSError subclass whose __init__ doesn't call back
1417
OSError.__init__ could produce incomplete instances, leading to crashes
1518
when calling str() on them.

Modules/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ Py_Main(int argc, wchar_t **argv)
660660
sts = run_command(command, &cf);
661661
free(command);
662662
} else if (module) {
663-
sts = RunModule(module, 1);
663+
sts = (RunModule(module, 1) != 0);
664664
}
665665
else {
666666

0 commit comments

Comments
 (0)