Support unittest.subTest context manager (Python 3.4+)
See original GitHub issueSummary
Python 3.4 added the unittest.subTest() context manager. It would be wonderful if Green elevated the information from subTest() up to the top level.
I think it’s best displayed with an example.
Example
Code (taken directly from the subTest() docs):
class NumbersTest(unittest.TestCase):
def test_even(self):
"""
Test that numbers between 0 and 5 are all even.
"""
for i in range(0, 6):
with self.subTest(i=i):
self.assertEqual(i % 2, 0)
Green’s output:
Unittest’s output:
See how the standard unittest module will show you (i=1)
, (i=3)
, and (i=5)
on the fail line?
Mockup:
Here’s a mockup of how Green might look when utilizing the subTest feature:
green project -vvv
I don’t think that the subTest items need to be displayed for lower verbosity levels. I also don’t think that each failed iteration needs the Traceback (like is done with unittest) unless verbosity is set to the highest level.
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
unittest — Unit testing framework — Python 3.11.1 ...
It supports test automation, sharing of setup and shutdown code for tests, aggregation of tests into collections, and independence of the tests from...
Read more >PyCharm 3.4 unittest subTest() does not fail - Stack Overflow
The context manager unittest.subTest() is new in Python 3.4. PyCharm 3.x does not support subTests yet. The support was added to PyCharm 4.0 ......
Read more >Subtests in Python - Paul Ganssle
Introduction. unittest.TestCase.subTest was originally introduced in Python 3.4 as a lightweight mechanism for test parameterization [1]; it ...
Read more >silx.utils.testutils — silx 0.7.0 documentation
subTest ` replacement for Python < 3.4 - :class:`TestLogging` with context or the ... Class attribute to provide a default value @contextlib.contextmanager.
Read more >Python unittest subtest
Introduction to the unittest subtest context manager ... The calculate() function calculates the net price from the price, tax, and discount. ... To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thanks guys, works a treat
Resolved in 2.11.0 (just released).