Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-127221: Add colour to unittest output#127223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
hugovk commented Nov 24, 2024 • edited by bedevere-app bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-app bot
Uh oh!
There was an error while loading. Please reload this page.
nineteendo commented Nov 24, 2024
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. :) |
hugovk commented Nov 24, 2024
You can click the images to open them full size. |
nineteendo commented Nov 24, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
AlexWaygood left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 d01272fCompare| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
hugovk commented Nov 24, 2024
AlexWaygood commented Nov 24, 2024
Nice, that looks great to me now! |
nineteendo commented Nov 24, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
AlexWaygood commented Nov 24, 2024
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? |
nineteendo commented Nov 24, 2024
Correct, with 3 images on the same row I can't read the text without zooming in. |
AlexWaygood commented Nov 24, 2024
I see. @hugovk, do you think we should add a link to the |
hugovk commented Nov 24, 2024
AlexWaygood left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Uh oh!
There was an error while loading. Please reload this page.
sobolevn left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
hugovk commented Nov 24, 2024
Misc/NEWS.d/next/Library/2024-11-23-00-17-29.gh-issue-127221.OSXdFE.rst Outdated Show resolvedHide resolved
Uh oh!
There was an error while loading. Please reload this page.
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/