Message254827
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. |
|
Date |
User |
Action |
Args |
2015-11-18 02:34:13 | ezio.melotti | set | recipients:
+ ezio.melotti, pitrou, rbcollins, michael.foord |
2015-11-18 02:34:13 | ezio.melotti | set | messageid: <1447814053.14.0.516761369725.issue25651@psf.upfronthosting.co.za> |
2015-11-18 02:34:12 | ezio.melotti | link | issue25651 messages |
2015-11-18 02:34:11 | ezio.melotti | create | |
|