[Python-checkins] bpo-39450 Stripped whitespace before parsing the docstring in TestCase.shortDescription (GH-18321)
Miss Islington (bot)
webhook-mailer at python.org
Mon Feb 3 02:25:24 EST 2020
https://github.com/python/cpython/commit/7561e7a83ccccf5118fda6c62fe9c8c3458f8cfd
commit: 7561e7a83ccccf5118fda6c62fe9c8c3458f8cfd
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-02-03T07:25:17Z
summary:
bpo-39450 Stripped whitespace before parsing the docstring in TestCase.shortDescription (GH-18321)
(cherry picked from commit 032de7324e30c6b44ef272cea3be205a3d768759)
Co-authored-by: Steve Cirelli <scirelli+git at gmail.com>
files:
A Misc/NEWS.d/next/Library/2020-02-02-14-46-34.bpo-39450.48R274.rst
M Lib/unittest/case.py
M Lib/unittest/test/test_case.py
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 811f5df23dd14..24af29057646a 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -493,7 +493,7 @@ def shortDescription(self):
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 6d58201ea8143..4fac8d5974528 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -610,6 +610,15 @@ def testShortDescriptionWithMultiLineDocstring(self):
'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 0000000000000..55fed519a2d80
--- /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`.
More information about the Python-checkins
mailing list