nose icon indicating copy to clipboard operation
nose copied to clipboard

Improve logcapture plugin: allow capture of output for successful tests

Open DerrickRice opened this issue 11 years ago • 15 comments

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.

DerrickRice avatar Apr 17 '13 13:04 DerrickRice

I too would like to see logging output for successful tests, optionally of course. in my case, to validate what unit test does manually.

dimaqq avatar Oct 03 '13 00:10 dimaqq

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?

avidas avatar Dec 31 '13 18:12 avidas

+1 on log capture on success, a verbose flag of some sort would be great

pykler avatar Apr 20 '14 01:04 pykler

Yes, same here. +1

erikbgithub avatar Aug 20 '14 12:08 erikbgithub

+1 I would love to have this too

whirm avatar Sep 11 '14 13:09 whirm

+1

dizballanze avatar Apr 02 '15 19:04 dizballanze

+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.

thijsvandien avatar Jun 18 '15 10:06 thijsvandien

Has there been any updates on this? Is this a feature that is going to be supported?

avidas avatar Jul 01 '15 18:07 avidas

@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.

jszakmeister avatar Jul 01 '15 22:07 jszakmeister

+1

Ankit-jhunjhunwala22 avatar Aug 27 '15 11:08 Ankit-jhunjhunwala22

+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

aliceinwire avatar Jan 02 '16 12:01 aliceinwire

+1 very frustrating to find out. it doesnt make sense to me not to show logging even when specifying --nologcapture ;/

belugame avatar Jan 23 '16 18:01 belugame

+1. Could we have a config option that captures logs even on success?

bbhavsar avatar Oct 19 '16 20:10 bbhavsar

The --debug flag is enough for me. See here.

villasv avatar Dec 09 '16 19:12 villasv

+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

ababushk avatar Jun 13 '18 18:06 ababushk