diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-02-03 08:20:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-03 08:20:41 (GMT) |
commit | 02395fad8e3a35ef00fa31c308693844013a1dd4 (patch) | |
tree | b8a4f6425a87206f0d1dced513883cdcc1fdbc3e | |
parent | 17236873392533ce0c5d7bbf52cbd61bca171c59 (diff) | |
download | cpython-02395fad8e3a35ef00fa31c308693844013a1dd4.zip cpython-02395fad8e3a35ef00fa31c308693844013a1dd4.tar.gz cpython-02395fad8e3a35ef00fa31c308693844013a1dd4.tar.bz2 |
bpo-39450 Stripped whitespace before parsing the docstring in TestCase.shortDescription (GH-18175) (#18323)
(cherry picked from commit 032de7324e30c6b44ef272cea3be205a3d768759)
Co-authored-by: Steve Cirelli <scirelli+git@gmail.com>
-rw-r--r-- | Lib/unittest/case.py | 2 | ||||
-rw-r--r-- | Lib/unittest/test/test_case.py | 9 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-02-02-14-46-34.bpo-39450.48R274.rst | 2 |
3 files changed, 12 insertions, 1 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index b639c64..e5734b6 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -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): diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index c2401c3..f855c4d 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -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.""" diff --git a/Misc/NEWS.d/next/Library/2020-02-02-14-46-34.bpo-39450.48R274.rst b/Misc/NEWS.d/next/Library/2020-02-02-14-46-34.bpo-39450.48R274.rst new file mode 100644 index 0000000..55fed51 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-02-02-14-46-34.bpo-39450.48R274.rst @@ -0,0 +1,2 @@ +Striped whitespace from docstring before returning it from +:func:`unittest.case.shortDescription`. |