nose
nose copied to clipboard
Improve logcapture plugin: allow capture of output for successful tests
Currently, logcapture uses formatError and formatFailure to extract the captured logging messages and (a) append them to the error text, which changes it from an error value to a string value and (b) tack the captured logging messages to the test instance.
For downstream plugins, this can be problematic for two reasons. Firstly, captured logging is not available for successful tests. Rather than suggesting the addition of formatSuccess (a larger change), I'd propose an architectural change to logcapture which makes logcapture data available via the test instance. The changes are:
- at beforeTest, set test.logcaptureData to an object which contains a reference to the log handler.
- move implementation for extracting textual captured logs to logcaptureData
- at afterTest, invoke logcaptureData.finish() which extracts textual captured logs and stores it in logcaptureData.text and removes the reference to handler.
This way, plugins are always able to invoke test.logcaptureData.getText() and it will use either the text attribute (if 'finished') or extract from the handler directly (if not yet finished).
The second problem is that logcapture changes errors into strings. If the client tests are written such that additional information is available via tests, this clobbers that information. I'd like to add a code-only (i.e. not an argument) flag to disable this behavior.
I'll provide a patch.
I too would like to see logging output for successful tests, optionally of course. in my case, to validate what unit test does manually.
Just ran into this issue and wanted to add on that it would be great to have logging capturing option for successful tests as well. Is this patch being considered?
+1 on log capture on success, a verbose flag of some sort would be great
Yes, same here. +1
+1 I would love to have this too
+1
+1 Actually this is the behavior I expected when setting the logging-level thinking DEFAULT would depend on success or failure, the default for success being NONE.
Has there been any updates on this? Is this a feature that is going to be supported?
@avidas Sorry, but I'll get to it when I get to it. Like most everyone else, I have a day job and a family--and there's a lot going on on both fronts.
+1
+1 what about using the streamhandler for send info to stderr and debug used only in failure ? using something like this http://stackoverflow.com/questions/2302315/how-can-info-and-debug-logging-message-be-sent-to-stdout-and-higher-level-messag
import logging
stream_handler = logging.StreamHandler(sys.__stderr__)
stream_handler.setFormatter(logging.Formatter('%(levelname)s :: '
'%(name)s :: %(message)s'))
log = logging.getLogger()
log.addHandler(stream_handler)
log.setLevel(logging.DEBUG)
log2 = logging.getLogger(__name__)
log2.setLevel(logging.DEBUG)
example:
..DEBUG :: print:: hello
+1 very frustrating to find out. it doesnt make sense to me not to show logging even when specifying --nologcapture ;/
+1. Could we have a config option that captures logs even on success?
The --debug
flag is enough for me. See here.
+1 for this we need this to create simple HTML plugin, but it seems that we need to use the same approach as XUnit plugin uses - write custom stdout grabber