New submission from Ezio Melotti:

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.

----------
components: Library (Lib)
keywords: easy
messages: 254827
nosy: ezio.melotti, michael.foord, pitrou, rbcollins
priority: normal
severity: normal
stage: test needed
status: open
title: Confusing output for TestCase.subTest(0)
type: behavior
versions: Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25651>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to