Console output folding? #8843
-
Hello, I am doing some investigation into the possibility of implementing a 'folding' capability for Pytest's console output, and wanted to ask here about the feasibility of this idea. My main motivator is the fact that, in the face of multiple test failures, and with the default behavior in place, the output can span many pages, requiring the tester to scroll back and hunt for the first failed test in the run. It is easy to get lost, and hard to pinpoint precisely where things started to go wrong. So I thought it would be helpful to have a capability that implements some sort of console 'folding', such that all the detailed Pytest console content is still available, just hidden by default - yet still able to be expanded in some way with operator interaction. [I don't know yet if "operator interaction" would be done with keyboard, mouse, or what.] I do know that Pytest already allows changing the level of verbosity, traceback info, etc. I am also aware of the pytest-html plugin, which is pretty much exactly what I am looking for, just in-console. Would appreciate some comments/advice...is this even do-able? I can't be the first person to dream of such a thing! Thanks, Jeff |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 16 replies
-
Hi @jeffwright13, That seems really useful, however it would require pytest's output to become interactive, which would be a separate application I believe. This certainly seems possible to implement as a plugin, perhaps using Rich? Anyway that is a neat idea. |
Beta Was this translation helpful? Give feedback.
-
Taking this here from above since it's a different approach at tackling the problem:
This would be amazing! Unfortunately, to my knowledge, there's no terminal which supports such a thing. That's why @nicoddemus said above that it essentially requires a pytest wrapper or plugin which moves away from the current console UI, instead providing an interactive, TUI-like interface. Perhaps @kovidgoyal with kitty would be interested in such a thing, given that it already has a lot of nice, advanced features (such as graphics rendering) other terminals typically don't? 😉 For some prior art, both Travis CI and GitHub Actions have such a feature, and there's a pytest-travis-fold plugin using it (see abusalimov/pytest-travis-fold#9 for GHA, as an aside). |
Beta Was this translation helpful? Give feedback.
-
On Fri, Jul 02, 2021 at 04:57:08AM -0700, Jeff Wright wrote:
> then when you open the report in the editor
Ahh, I see what you are saying. I somehow missed the part about using an editor to look at the results. ==> I blame not having had any coffee yet today. <==
My original idea was to implement something that allowed folding in the same console in which the `pytest` invocation was done in the first place - something that did not require having to open an external program. Because by the time I do that, I could have just as easily used pytest-html and opened the results in a browser, no?
The editor runs in the same console as pytest, its a terminal program.
You are going to need *something* that draws a UI in the console. You
can of course write your own code to do it, but seems a lot of work
and people that actually use terminals heavily would probably prefer
navigating the scrollback in an editor they use anyway. This is why
kitty has the facility to open its scrollback in a pager/editor.
|
Beta Was this translation helpful? Give feedback.
-
On Fri, Jul 02, 2021 at 06:33:23AM -0700, Jeff Wright wrote:
> You are going to need *something* that draws a UI in the console.
With this envisioned new feature/plugin/whatever, I might be able to say something like `pytest --fold test_example.py' and even though many failed test results might be shown in the console, at least they are now only one line each, instead of 12 lines each, and now (here is the kicker), I can unfold/fold results as needed. Very much like the way Robot Framework does it, if you are familiar with that tool.
In my mind, at least, this would be a time-saver and much more convenient than having to launch a browser or an editor to look at the results.
py test would open the editor *for you automatically*, with all but
failing tests folded, with the cursor positioned at the first failed
test, *in the console*. You would not have to do anything but marvel at
its awesomeness.
|
Beta Was this translation helpful? Give feedback.
-
On Fri, Jul 02, 2021 at 07:14:18AM -0700, Jeff Wright wrote:
OK, so that is cool, at least from a "MVP" (minimum viable product) standpoint. Might be a good place to start to get my feet wet, at least.
Questions and concerns:
- Regarding @flub 's comment that it is not generally a good idea to rely on any specific output format - I would like to take that into account, especially since the user can modify the output format drastically with execution flags like `-v`, `--tb`, etc. Do you have any insight into this, with your proposed solution in mind?
I dont actually use pytest so I have no clue, my solution requires all
foldable parts of the output to be surrounded by fold markers.
- I'm not in love with the idea of prompting a question to the tester at the end of a run, so perhaps just setting the EDITOR environment variable, as you suggested, or maybe specifying the editor via command line flag, would be an alternative...and the editor would automagically appear if conmfigured, otherwise the output would be as usual.
Sure use a command line option.
- Any special considerations for non-Linux/Mac users, who won't have vi/vim available?
Have an option/config/env var (aka EDITOR) to specify the editor. If you
cant find the editor to execute just print an error about it at the end
of the normal output.
- Any special considerations for DOS/WIndows vs. Linux/Mac EOL characters?
Most editors handle those automatically.
|
Beta Was this translation helpful? Give feedback.
-
I finally had some time to put together a POC (Proof of Concept) for this. Please see https://github.com/jeffwright13/pytest-fold for source code. Yes, I know, very hacky in places. :-) And here is a screencast of I've been up-close with this for so long now that I don't even know if it's anything anybody will ever want to use. Feedback welcome! |
Beta Was this translation helpful? Give feedback.
I finally had some time to put together a POC (Proof of Concept) for this. Please see https://github.com/jeffwright13/pytest-fold for source code. Yes, I know, very hacky in places. :-)
And here is a screencast of
pytest-fold
in action: https://drive.google.com/file/d/1kbyI_e5lPQmVBv_v-QvyTDNT4zlRZtIW/view?usp=sharingI've been up-close with this for so long now that I don't even know if it's anything anybody will ever want to use. Feedback welcome!