Message180221
subtests are a light alternative to parametered tests as in issue7897. They don't generate the tests for you, they simply allow to partition a given test case in several logical units. Meaning, when a subtest fails, the other subtests in the test will still run (and the failures will print their respective parameters).
Concretely, running the follow example:
class MyTest(unittest.TestCase):
def test_b(self):
"""some test"""
for i in range(2, 5):
for j in range(0, 3):
with self.subTest(i=i, j=j):
self.assertNotEqual(i % 3, j)
will give the following output:
======================================================================
FAIL: test_b (__main__.MyTest) (i=2, j=2)
some test
----------------------------------------------------------------------
Traceback (most recent call last):
File "subtests.py", line 11, in test_b
self.assertNotEqual(i % 3, j)
AssertionError: 2 == 2
======================================================================
FAIL: test_b (__main__.MyTest) (i=3, j=0)
some test
----------------------------------------------------------------------
Traceback (most recent call last):
File "subtests.py", line 11, in test_b
self.assertNotEqual(i % 3, j)
AssertionError: 0 == 0
======================================================================
FAIL: test_b (__main__.MyTest) (i=4, j=1)
some test
----------------------------------------------------------------------
Traceback (most recent call last):
File "subtests.py", line 11, in test_b
self.assertNotEqual(i % 3, j)
AssertionError: 1 == 1
---------------------------------------------------------------------- |
|
Date |
User |
Action |
Args |
2013-01-18 21:07:11 | pitrou | set | recipients:
+ pitrou, spiv, exarkun, ncoghlan, ezio.melotti, eric.araujo, r.david.murray, michael.foord, brian.curtin, hpk, fperez, chris.jerdonek, Yaroslav.Halchenko, santoso.wijaya, nchauvat, kynan, Julian, abingham, eric.snow, borja.ruiz, bfroehle |
2013-01-18 21:07:11 | pitrou | set | messageid: <1358543231.78.0.354364612897.issue16997@psf.upfronthosting.co.za> |
2013-01-18 21:07:11 | pitrou | link | issue16997 messages |
2013-01-18 21:07:11 | pitrou | create | |
|