changeset: 104000:e5888f5b9cf8 parent: 103996:87da80a56f94 parent: 103999:ddbf92168a44 user: Berker Peksag date: Wed Sep 21 19:35:54 2016 +0300 files: Misc/NEWS description: Issue #25651: Merge from 3.6 diff -r 87da80a56f94 -r e5888f5b9cf8 Lib/unittest/case.py --- a/Lib/unittest/case.py Wed Sep 21 17:12:50 2016 +0200 +++ b/Lib/unittest/case.py Wed Sep 21 19:35:54 2016 +0300 @@ -17,6 +17,7 @@ __unittest = True +_subtest_msg_sentinel = object() DIFF_OMITTED = ('\nDiff is %s characters long. ' 'Set self.maxDiff to None to see it.') @@ -497,7 +498,7 @@ result.addSuccess(test_case) @contextlib.contextmanager - def subTest(self, msg=None, **params): + def subTest(self, msg=_subtest_msg_sentinel, **params): """Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters. A failure in the subtest marks the test @@ -1397,7 +1398,7 @@ def _subDescription(self): parts = [] - if self._message: + if self._message is not _subtest_msg_sentinel: parts.append("[{}]".format(self._message)) if self.params: params_desc = ', '.join( diff -r 87da80a56f94 -r e5888f5b9cf8 Lib/unittest/test/test_result.py --- a/Lib/unittest/test/test_result.py Wed Sep 21 17:12:50 2016 +0200 +++ b/Lib/unittest/test/test_result.py Wed Sep 21 19:35:54 2016 +0300 @@ -323,6 +323,16 @@ 'testGetSubTestDescriptionWithoutDocstringAndParams ' '(' + __name__ + '.Test_TestResult) ()') + def testGetSubTestDescriptionForFalsyValues(self): + expected = 'testGetSubTestDescriptionForFalsyValues (%s.Test_TestResult) [%s]' + result = unittest.TextTestResult(None, True, 1) + for arg in [0, None, []]: + with self.subTest(arg): + self.assertEqual( + result.getDescription(self._subtest), + expected % (__name__, arg) + ) + def testGetNestedSubTestDescriptionWithoutDocstring(self): with self.subTest(foo=1): with self.subTest(bar=2): diff -r 87da80a56f94 -r e5888f5b9cf8 Misc/NEWS --- a/Misc/NEWS Wed Sep 21 17:12:50 2016 +0200 +++ b/Misc/NEWS Wed Sep 21 19:35:54 2016 +0300 @@ -41,6 +41,8 @@ Library ------- +- Issue #25651: Allow falsy values to be used for msg parameter of subTest(). + - Issue #27778: Fix a memory leak in os.getrandom() when the getrandom() is interrupted by a signal and a signal handler raises a Python exception.