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

diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index fa64a6e..5e5d535 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -512,7 +512,7 @@
         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 @@
                  '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."""