[3.11] gh-102541: Fix Helper.help("mod") for non-existent mod (GH-105934) (#106323)

gh-102541: Fix Helper.help("mod") for non-existent mod (GH-105934)

If the output arg to Helper() is a stream rather than the default None, which means 'page to stdout', the ImportError from pydoc.resolve is currently not caught in pydoc.doc. The same error is caught when output is None.
---------

(cherry picked from commit 0530f4f646)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Miss Islington (bot) 2023-07-01 16:15:44 -07:00 committed by GitHub
parent f5e29f4245
commit 9e33586018
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View file

@ -631,6 +631,13 @@ class PydocDocTest(unittest.TestCase):
# Testing that the subclasses section does not appear
self.assertNotIn('Built-in subclasses', text)
def test_fail_help_output_redirect(self):
with StringIO() as buf:
helper = pydoc.Helper(output=buf)
helper.help("abd")
expected = missing_pattern % "abd"
self.assertEqual(expected, buf.getvalue().strip().replace('\n', os.linesep))
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
'trace function introduces __locals__ unexpectedly')
@requires_docstrings