question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support unittest.subTest context manager (Python 3.4+)

See original GitHub issue

Summary

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:

image

Unittest’s output:

image

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

image

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:closed
  • Created 8 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
lsh-0commented, Sep 29, 2017

thanks guys, works a treat

1reaction
CleanCutcommented, Aug 11, 2017

Resolved in 2.11.0 (just released).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found