-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
gh-127221: Add colour to unittest output #127223
base: main
Are you sure you want to change the base?
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. |
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
d01272f
Compare
@@ -106,6 +107,7 @@ def cleanup2(*args, **kwargs): | |||
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!
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 |
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!
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?
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>
Use the existing
_colorize
module already used for tracebacks and doctest so output can be controlled with thePYTHON_COLORS
,NO_COLOR
andFORCE_COLOR
environment variables.This PR does a couple of things to add colour:
colorize
tomsgLines = 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/