mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
bpo-30664: The description of a unittest subtest now preserves the (#2265)
order of keyword arguments of TestCase.subTest().
This commit is contained in:
parent
c38e32a100
commit
48fbe52ac7
3 changed files with 29 additions and 7 deletions
|
@ -307,7 +307,7 @@ class Test_TestResult(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
result.getDescription(self._subtest),
|
||||
'testGetSubTestDescriptionWithoutDocstring (' + __name__ +
|
||||
'.Test_TestResult) (bar=2, foo=1)')
|
||||
'.Test_TestResult) (foo=1, bar=2)')
|
||||
with self.subTest('some message'):
|
||||
result = unittest.TextTestResult(None, True, 1)
|
||||
self.assertEqual(
|
||||
|
@ -335,12 +335,21 @@ class Test_TestResult(unittest.TestCase):
|
|||
|
||||
def testGetNestedSubTestDescriptionWithoutDocstring(self):
|
||||
with self.subTest(foo=1):
|
||||
with self.subTest(bar=2):
|
||||
with self.subTest(baz=2, bar=3):
|
||||
result = unittest.TextTestResult(None, True, 1)
|
||||
self.assertEqual(
|
||||
result.getDescription(self._subtest),
|
||||
'testGetNestedSubTestDescriptionWithoutDocstring '
|
||||
'(' + __name__ + '.Test_TestResult) (bar=2, foo=1)')
|
||||
'(' + __name__ + '.Test_TestResult) (baz=2, bar=3, foo=1)')
|
||||
|
||||
def testGetDuplicatedNestedSubTestDescriptionWithoutDocstring(self):
|
||||
with self.subTest(foo=1, bar=2):
|
||||
with self.subTest(baz=3, bar=4):
|
||||
result = unittest.TextTestResult(None, True, 1)
|
||||
self.assertEqual(
|
||||
result.getDescription(self._subtest),
|
||||
'testGetDuplicatedNestedSubTestDescriptionWithoutDocstring '
|
||||
'(' + __name__ + '.Test_TestResult) (baz=3, bar=4, foo=1)')
|
||||
|
||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||
"Docstrings are omitted with -O2 and above")
|
||||
|
@ -362,7 +371,7 @@ class Test_TestResult(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
result.getDescription(self._subtest),
|
||||
('testGetSubTestDescriptionWithOneLineDocstring '
|
||||
'(' + __name__ + '.Test_TestResult) (bar=2, foo=1)\n'
|
||||
'(' + __name__ + '.Test_TestResult) (foo=1, bar=2)\n'
|
||||
'Tests getDescription() for a method with a docstring.'))
|
||||
|
||||
@unittest.skipIf(sys.flags.optimize >= 2,
|
||||
|
@ -390,7 +399,7 @@ class Test_TestResult(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
result.getDescription(self._subtest),
|
||||
('testGetSubTestDescriptionWithMultiLineDocstring '
|
||||
'(' + __name__ + '.Test_TestResult) (bar=2, foo=1)\n'
|
||||
'(' + __name__ + '.Test_TestResult) (foo=1, bar=2)\n'
|
||||
'Tests getDescription() for a method with a longer '
|
||||
'docstring.'))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue