Message180221
| Author |
pitrou |
| Recipients |
Julian, Yaroslav.Halchenko, abingham, bfroehle, borja.ruiz, brian.curtin, chris.jerdonek, eric.araujo, eric.snow, exarkun, ezio.melotti, fperez, hpk, kynan, michael.foord, nchauvat, ncoghlan, pitrou, r.david.murray, santoso.wijaya, spiv |
| Date |
2013年01月18日.21:07:11 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1358543231.78.0.354364612897.issue16997@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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
---------------------------------------------------------------------- |
|
History
|
|---|
| 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 |
|