This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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:11pitrousetrecipients: + 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:11pitrousetmessageid: <1358543231.78.0.354364612897.issue16997@psf.upfronthosting.co.za>
2013-01-18 21:07:11pitroulinkissue16997 messages
2013-01-18 21:07:11pitroucreate