__unittest = True
+_subtest_msg_sentinel = object()
DIFF_OMITTED = ('\nDiff is %s characters long. '
'Set self.maxDiff to None to see it.')
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
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(
'testGetSubTestDescriptionWithoutDocstringAndParams '
'(' + __name__ + '.Test_TestResult) (<subtest>)')
+ 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):
Library
-------
+- Issue #25651: Allow falsy values to be used for msg parameter of subTest().
+
- Issue #27932: Prevent memory leak in win32_ver().
- Fix UnboundLocalError in socket._sendfile_use_sendfile.