8000 bpo-39450 Stripped whitespace before parsing the docstring in TestCas… · python/cpython@02395fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 02395fa

Browse files
bpo-39450 Stripped whitespace before parsing the docstring in TestCase.shortDescription (GH-18175) (#18323)
(cherry picked from commit 032de73) Co-authored-by: Steve Cirelli <scirelli+git@gmail.com>
1 parent 1723687 commit 02395fa

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Lib/unittest/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def shortDescription(self):
529529
the specified test method's docstring.
530530
"""
531531
doc = self._testMethodDoc
532-
return doc and doc.split("\n")[0].strip() or None
532+
return doc.strip().split("\n")[0].strip() if doc else None
533533

534534

535535
def id(self):

Lib/unittest/test/test_case.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,15 @@ def testShortDescriptionWithMultiLineDocstring(self):
610610
'Tests shortDescription() for a method with a longer '
611611
'docstring.')
612612

613+
def testShortDescriptionWhitespaceTrimming(self):
614+
"""
615+
Tests shortDescription() whitespace is trimmed, so that the first
616+
line of nonwhite-space text becomes the docstring.
617+
"""
618+
self.assertEqual(
619+
self.shortDescription(),
620+
'Tests shortDescription() whitespace is trimmed, so that the first')
621+
613622
def testAddTypeEqualityFunc(self):
614623
class SadSnake(object):
615624
"""Dummy class for test_addTypeEqualityFunc."""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Striped whitespace from docstring before returning it from
2+
:func:`unittest.case.shortDescription`.

0 commit comments

Comments
 (0)
0