Index: Lib/pydoc.py =================================================================== --- Lib/pydoc.py (revision 73093) +++ Lib/pydoc.py (working copy) @@ -300,7 +300,7 @@ # A SyntaxError occurred before we could execute the module. raise ErrorDuringImport(value.filename, info) elif exc is ImportError and \ - split(lower(str(value)))[:2] == ['no', 'module']: + split(str(value)) == ['No', 'module', 'named', path]: # The module was not found. return None else: Index: Lib/test/badimport_module.py =================================================================== --- Lib/test/badimport_module.py (revision 0) +++ Lib/test/badimport_module.py (revision 0) @@ -0,0 +1,4 @@ +""" +Module with bad import. See issue #5230 +""" +import this_is_not_a_module Index: Lib/test/test_pydoc.py =================================================================== --- Lib/test/test_pydoc.py (revision 73093) +++ Lib/test/test_pydoc.py (working copy) @@ -166,6 +166,9 @@ # output pattern for missing module missing_pattern = "no Python documentation found for '%s'" +# output pattern for module with bad imports +badimport_pattern = "problem in %s - : No module named %s" + def run_pydoc(module_name, *args): """ Runs pydoc on the specified module. Returns the stripped @@ -237,6 +240,13 @@ self.assertEqual(expected, result, "documentation for missing module found") + def test_badimport(self): + badimport_module = "badimport_module" + result = run_pydoc(badimport_module) + expected = badimport_pattern % (badimport_module, "this_is_not_a_module") + self.assertEqual(expected, result, + "documentation for module with bad import found") + def test_input_strip(self): missing_module = " test.i_am_not_here " result = run_pydoc(missing_module)