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
enhance unittest to show test name and docstring on one line #91289
Comments
|
When running unittest with the -v flag, if a test has errors, and has a docstring, the test name is shown on one line, and the docstring is shown on the next line -- and the ERROR word is shown with the docstring. What this means is that:
There are two possible solutions, and the selection of which one should be discussed on python-dev:
--- For the experienced developers who see this: please leave the issue for one of the new developers subscribed to core-mentorship. Thank you. |
|
I would like to work on this. |
|
I don't think this change of behaviour should be accepted without discussion, and I'm not sure why you think Python-Dev is the right place, rather than here. Messing around with unittest and docstrings has already caused issues in the past: https://docs.python.org/3/library/unittest.html#unittest.TestCase.shortDescription so perhaps we shouldn't break what's not broken? And frankly, I don't see why the current behaviour is a problem, although maybe that's because the way I use unittest is different from the way you use it. Grepping the output for errors? Why run verbose mode if you aren't going to read the whole output? Seems very odd. Ethan says: "the test name is easily missed by anyone who isn't aware of that" Surely the solution to that is education, not changing unittest? Now you are aware of it, and the test name is no longer "easily missed". If it ever was. To me, it is plain as day. Here is some typical output: [steve ~]$ python3.10 -m unittest -v mathlib/testing/test_utils.py ====================================================================== Traceback (most recent call last):
File "/home/steve/Desktop/mathlib/testing/test_utils.py", line 20, in test_broken_doc
self.assertEqual(1, x)
NameError: name 'x' is not defined====================================================================== Traceback (most recent call last):
File "/home/steve/Desktop/mathlib/testing/test_utils.py", line 24, in test_broken_nodoc
self.assertEqual(1, x)
NameError: name 'x' is not definedRan 10 tests in 0.004s FAILED (errors=2) Errors are listed twice, once in the summary, and the second time in the details section showing the traceback. Note that if you just grep for ERROR you get the result you want: [steve ~]$ python3.10 -m unittest -v mathlib/testing/test_utils.py |& grep ERROR So I am having trouble seeing what the problem here is. |
|
I proposed a discussion to python-dev to increase the odds that folks with an interest could chime in. Not everyone follows the new-bugs list. I find having the output on two lines counter-intuitive -- I was expecting one line per test, and indeed my experience seemed to support that (out of hundreds of tests showing on one line, it's easy to miss that the rare verbose error is on two). And I'm not the only one, since another developer also thought there was a problem and spent most of bpo-46126 "fixing" it. Another reason for posting to python-dev is that bpo-46126 had been active for three months and had a PR merged before another dev mentioned that verbose tests with docstrings just printed on two lines instead of one. Thank you for pointing out the possible disruption caused by unittest output changes. |
|
I have no problem with pinging Python-Dev, or any other forum, asking Aside from the conservative position "If it ain't broke, don't break https://matt-rickard.com/chestertons-fence/ I'm not specifically opposed to this change. Nor am I in favour. Why do we print the first line of the doctests in the output of failing I am -1 on another option flag unless there is no other choice. Each Another option might be to leave the docstring line alone, and just That seems to me to be less risky than trying to cram them all on one line. By the way, I presume we do the same thing for FAIL lines, which have |
|
This is already the third (at least) issue asking for such feature. Many people have problems with the current output. I would prefer to have a full qualified name of the test which I can copy by a double click and insert in a command that reruns specified tests. And full path to the test's source which I can copy to run in editor. pytest output looks more user-friendly to me. But it may break other's test output parsers so we perhaps need an option for this. Options for unittest and libregrtest. I am not sure that it is a task for an average new contributor. |
|
Rather than an option for this, it would be cleaner to deprecate the Otherwise we have to maintain the old (bad?) output and the new output |
|
A more fundamental issue behind this: unittest's plain text verbose output is not intended to be parsable and consumable by machines. It is 22 years old and was intended for use in 80 column wide terminals as a progress report while watching it run as much it is a final result. Consider that the legacy use case or format if you wish. Allowing an option for output to one line per test with description could be more likely to require horizontal scrolling or reading past a line wrap in CI setups where text is scrolling regions embedded in scrolling regions. Yuck. BUT not necessarily bad. Just different. The ideas expressed in this thread of making a more clear text format with the important PASS/FAIL/ERROR/SKIP status up front and a very clear pastable test module.class.test_name seem wise. I expect most Python projects with nicer test output formatting desires have simply adopted pytest and never looked back. --- Other python unittest derivative concepts to get clear output of results: We add a reliably machine parsable XML report of test outcomes in absl-py https://github.com/abseil/abseil-py/tree/main/absl/testing. It's IMNSHO a rather annoying implementation - we wish unittest made plugging in additional output formats easier. We use that generated XML format for results from unittest systems in all of our languages at work, it is picked up and parsed by our internal CI system and used to display nicely formatted results when available. I assume pytest also provides machine parsable reporting capabilities but I haven't looked. |
|
Hey @ethanfurman I am interested in working on this issue, I am new to opensource can you please explain where the changes have to be made. Also what exactly is needed to be done. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: