Index: Lib/pydoc.py =================================================================== --- Lib/pydoc.py (revision 73106) +++ 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', split(path, '.')[-1]]: # The module was not found. return None else: Index: Lib/test/pydoc_badimport.py =================================================================== --- Lib/test/pydoc_badimport.py (revision 0) +++ Lib/test/pydoc_badimport.py (revision 0) @@ -0,0 +1,4 @@ +""" +Module with bad import. See issue #5230 +""" +import this_is_not_a_module Index: Lib/test/pydoc_nothere2/__init__.py =================================================================== --- Lib/test/pydoc_nothere2/__init__.py (revision 0) +++ Lib/test/pydoc_nothere2/__init__.py (revision 0) @@ -0,0 +1,3 @@ +""" +A module for pydoc testing. See issue #5230 +""" Index: Lib/test/test_pydoc.py =================================================================== --- Lib/test/test_pydoc.py (revision 73106) +++ 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,20 @@ self.assertEqual(expected, result, "documentation for missing module found") + def test_not_here2(self): + missing_module = "pydoc_nothere2.this_cannot_possibly_be_a_module" + result = run_pydoc(missing_module) + expected = missing_pattern % missing_module + self.assertEqual(expected, result, + "documentation for missing module found") + + def test_badimport(self): + badimport_module = "pydoc_badimport" + 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)