-
Notifications
You must be signed in to change notification settings - Fork 116
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
transcripts do not catch errors #1185
Comments
@tleonhardt @anselor |
@kmvanbrunt The transcripts feature is an area of cmd2 I haven't really touched. At a high level I see no reason why it would be a problem. |
@kmvanbrunt I would be happy to see a more robust solution, but currently cmd2 transcripts do not actually capture stdout, they only capture the output of In other words, if you have two commands like:
and run you see this:
but if you create a transcript with:
then the transcript.txt looks like:
so the print output is missing. If you can figure out how to actually capture stdout, that would be great. But if not, maybe capturing |
@crotwell Transcripts capture everything written to Transcripts also already capture See this code here: https://github.com/python-cmd2/cmd2/blob/master/cmd2/cmd2.py#L4998 Your original PR probably has the simplest approach for filtering user-printed messages from other @duck-rh Can you clarify why you want If we start evaluating both streams in a transcript test, what happens when a test case writes to both streams? How will the transcript differentiate what text in a transcript belongs to @tleonhardt Thoughts? |
OK, I see the clarification. You said capturing I do not care about stderr being in the transcript, intermingling stdout and stderr is probably hard and error prone. And I guess there could be cases where self.stderr was not an actual failure, so Basically, I went with the simple Line 2871 in 5ce3a64
Currently there is an odd mixture of sometimes "bad things" are exceptions and sometimes they are just |
cmd2 does not have a The question I have is about the purpose of transcripts. I've not really used them nor have I contributed much to the transcript code, so my thoughts here might be incorrect. It seems like transcripts are about capturing expected output. When you generate them using |
That purpose for transcripts seems correct to me. But it is unclear to me if a transcript of something that writes to both stdout and stderr would be usable as a test in that how stdout and stderr are intermingled could be non-deterministic. It might be worth trying, but I don't know enough about python internals to know if you might effectively create a race condition between stdout and stderr if you try to combine them, especially in cases where there was a call to the shell. |
@kmvanbrunt yes, that's exactly it, I'm running unit tests. I don't see any other way to test the UI part of my application. I create a complete test environment and I want to make sure the flow of a command ends up with the proper result, whether it's a result or an error. I also have scenarios with a suite of commands having a specific outcome. You can have a look at what it looks like here: https://vcs-git.duckcorp.org/duckcorp/ldapwalker (branch |
@duck-rh |
@anselor thanks for pointing this out I must have missed it. I made a quick test and that seem to work fine. I noticed that plugins are not included in the distribution and I had to copy the module in my sources to make it work. Would it be possible to distribute them? |
@duck-rh It's distributed as a separate wheel you can import for your tests. |
PR #1210 I think addresses part of this, at least my concern about a transcript with a non-existant command returning "ok". Does not take care of capturing stderr when creating a transcript with history, not sure how important that is. Basically I borrowed code from cmd2-ext-test to use pybridge to grab stderr and concat it with stdout for the result. Simple concat might not be the right way to go, but at least something is there. Anyway, hope this helps... |
Quack,
I'm using cmd2 2.3.3 on Python 3.9.9 on Debian unstable.
I am trying to test my application using transcripts. Depending on the gravity of the situation it uses
pwarning()
orperror()
to alert the user but these calls are not caught by transcript and looking at the code of_generate_transcript
is seems only stdout is captured.I believe testing application checks are useful and in most test framework you can catch exceptions; would you consider capturing stderr too in the transcript?
Regards.
\_o<
The text was updated successfully, but these errors were encountered: