bpo-39450 Stripped whitespace before parsing the docstring in TestCase.shortDescription (GH-18175) (#18323)

(cherry picked from commit 032de7324e)

Co-authored-by: Steve Cirelli <scirelli+git@gmail.com>
This commit is contained in:
Miss Islington (bot) 2020-02-03 00:20:41 -08:00 committed by GitHub
parent 1723687339
commit 02395fad8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -529,7 +529,7 @@ class TestCase(object):
the specified test method's docstring.
"""
doc = self._testMethodDoc
return doc and doc.split("\n")[0].strip() or None
return doc.strip().split("\n")[0].strip() if doc else None
def id(self):

View File

@ -610,6 +610,15 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
'Tests shortDescription() for a method with a longer '
'docstring.')
def testShortDescriptionWhitespaceTrimming(self):
"""
Tests shortDescription() whitespace is trimmed, so that the first
line of nonwhite-space text becomes the docstring.
"""
self.assertEqual(
self.shortDescription(),
'Tests shortDescription() whitespace is trimmed, so that the first')
def testAddTypeEqualityFunc(self):
class SadSnake(object):
"""Dummy class for test_addTypeEqualityFunc."""

View File

@ -0,0 +1,2 @@
Striped whitespace from docstring before returning it from
:func:`unittest.case.shortDescription`.