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 ezio.melotti
Recipients ezio.melotti, michael.foord, pitrou, rbcollins
Date 2015-11-18.02:34:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1447814053.14.0.516761369725.issue25651@psf.upfronthosting.co.za>
In-reply-to
Content
When a single positional argument is passed to subTest(), if the argument is false, its value won't be displayed in the output -- (<subtest>) will appear instead:

>>> import unittest
>>> class NumbersTest(unittest.TestCase):
...   def test_odd(self):
...     for i in range(4):
...       with self.subTest(i):  # single positional arg
...         self.assertNotEqual(i%2, 0)
... 
>>> unittest.main(exit=False)
======================================================================
FAIL: test_odd (__main__.NumbersTest) (<subtest>)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<stdin>", line 5, in test_odd
AssertionError: 0 == 0
======================================================================
FAIL: test_odd (__main__.NumbersTest) [2]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<stdin>", line 5, in test_odd
AssertionError: 0 == 0
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (failures=2)

This is because subTest() accepts a positional "msg" arg, passes it to _SubTest (Lib/unittest/case.py:515), and then _SubTest checks using "if self._message:" (Lib/unittest/case.py:1400).

I think it would be better to check the message against a sentinel value instead.
History
Date User Action Args
2015-11-18 02:34:13ezio.melottisetrecipients: + ezio.melotti, pitrou, rbcollins, michael.foord
2015-11-18 02:34:13ezio.melottisetmessageid: <1447814053.14.0.516761369725.issue25651@psf.upfronthosting.co.za>
2015-11-18 02:34:12ezio.melottilinkissue25651 messages
2015-11-18 02:34:11ezio.melotticreate