gh-127221: Add colour to unittest output#127223
Conversation
|
Looks good, I see you're taking some inspiration from pytest, but I had to zoom in all the way to be able to read the text. :) |
|
You can click the images to open them full size. |
|
Well, I wanted to compare the images so I had to zoom in to see the difference. Maybe we could only show the comparison between pytest? The uncoloured images don't add much value. |
AlexWaygood
left a comment
There was a problem hiding this comment.
This is great!! With the coloured tracebacks as well, though, I sort-of feel like there might be a bit too much colour now when tests fail. It feels slightly overwhelming!
What about making only the "ERROR"/"FAIL"/"UNEXPECTED SUCCESS" lines coloured red, and not the ======= line above or the ------- below?
e18da3e to
d01272f
Compare
| self.assertTrue(test.doCleanups()) | ||
| self.assertEqual(cleanups, [(2, (), {}), (1, (1, 2, 3), dict(four='hello', five='goodbye'))]) | ||
|
|
||
| @force_not_colorized |
There was a problem hiding this comment.
we have to apply this decorator to so many methods that I almost wonder if it's worth having a custom metaclass that automatically adds it to each method on the class... or we could not use the @force_not_colorized decorator, and instead duplicate the logic in setUp and tearDown methods on the TestCleanup class here.
Neither feels ideal; it might be that what you have now is in fact best!
|
Nice, that looks great to me now! |
To be clear @nineteendo, this is a comment on the table in Hugo's PR description rather than the code he's changing in this PR, correct? |
|
Correct, with 3 images on the same row I can't read the text without zooming in. |
|
I see. @hugovk, do you think we should add a link to the |
sobolevn
left a comment
There was a problem hiding this comment.
Thank you! I like the idea. But, I personally feel like it is still a bit too colorful. Right now almost nothing is white.
One more idea: can you please test this with the white theme as well?
Misc/NEWS.d/next/Library/2024-11-23-00-17-29.gh-issue-127221.OSXdFE.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>


















Use the existing
_colorizemodule already used for tracebacks and doctest so output can be controlled with thePYTHON_COLORS,NO_COLORandFORCE_COLORenvironment variables.This PR does a couple of things to add colour:
colorizetomsgLines = list(tb_e.format(colorize=can_colorize()))Tested with some small demo scripts:
No tests ran
run-unittests-none.py
Passed
run-unittests-pass.py
Failing
run-unittests.py
Subtests
run-unittests-subtests.py
📚 Documentation preview 📚: https://cpython-previews--127223.org.readthedocs.build/