-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Proposal: disable "live logging" by default and write to terminal writer instead #3013
Comments
I would introduce a logcapture (or log-capture) property instead, similar to the existing capture property. In the course of changing the property(ies) of the logging plugin I would also rename the If we use the TerminalWriter for outputting the logs, we could hopefully write a newline character before the first log message s.t. loglines do not appear on the same lines as the testname. This is how it looks when capturing is turned off:
|
You mean a command-line option? I ask because the "capture" configuration that exists today is Having said that, I still would like a separate option for "live logs": seems useful to be able to be able to capture logs and only having them appear on the captured output section if a test fails. How about:
(Alternatively, all those could be |
Yes I mean a command line I don't understand why you need an additional |
(@Thisch sorry for the delay)
At first glance it might seem like it is but disabling the plugin entirely means that the
When I wrote the previous proposal, I was considering that But I'm thinking that having Perhaps we can have three values for
I'm also curious, do people use the live logs feature frequently? Also would love to hear other opinions on this. |
I like this, but I'm not sure if |
The output by TerminalWriter is captured if |
This is happening because of we are setting the log-level of the capture-per-item to NO_SET, which causes it to capture everything... this seems like a bad idea in general.
TerminalWriter is responsible for writing pytest's own output, so its output is not captured. |
Ok, so if we set the default |
I've tried to experiment a bit with TerminalWriter in twmr@6e3ddf8 but I can't get the logs to be shown when |
Ouch sorry, I meant the |
As demonstrated in #3035, the logging plugin as it stands now generates a lot of overhead in suites which make heavy use of logging: import logging
import pytest
def add(a, b):
logging.info(str(a))
return a + b
@pytest.mark.parametrize("a", range(1000))
def test_add(a):
for b in range(1000):
assert a + b == add(a, b) The difference between logging and no logging (using I don't think the problem is just the default log level, because I get similar times even when using |
@nicoddemus looking at our codebase where I have spotted the problem, we do not generate a lot of logging by default and we have switch for pytest:
It seems that 3.3.0 ignores that and logs everything. |
@skontar thanks, I think it currently overwrites the global settings in favor of its internal settings; another thing to consider. |
@nicoddemus also it seems to me that it stores logging of all tests, even the ones which passed, you can see it linearly grows in memory. I thought that you can throw away the log messages generated during passing tests? But it is probably tied to our usecase and would not be acceptable generally. |
When using the terminal it makes sense, but I think it is kept there so other plugins can access it and optionally make use of that information. |
I saw this exact same thing with some stress tests (quite frustrating and confusing). @nicoddemus @Thisch why can't logging capture simply be disabled by default unless test code demands the Stress tests are a prime example of where you don't want much logging emitted. Currently I see no way to combine such tests alongside Also,
IMHO ^ that's super wrong. |
To show logs when a test fails I assume? |
@The-Compiler showing or not showing logs imo should be independent of whether they're captured. It's not even really the logging itself that's the the problem is that the level set by test code isn't properly used when capturing is enabled. Setting a crazy low logging level by default is just super unexpected and as we've seen gives major performance headaches. |
@tgoodlet
I'm not sure I understand, how will we display the logs (after all tests have run, in the summary section, mind you) without capturing them? Could you elaborate please?
I agree, we should probably do not touch the root logger's level unless it is explicitly set by the |
@nicoddemus afaiu there's 2 toggles:
What I originally wrote:
To which @The-Compiler responded:
But there is no need to enable log |
Ok after reading
Why:
|
Hi @tgoodlet, thanks for the comments.
I agree it should not write to
I agree, we should only touch the root loggers level if the user explicitly sets
This could be done by a mark, but by default it should capture the root logger I think: the idea is that you get useful log messages when a test fail without the need to preemptively marks the tests where that information could be useful.
I'm not sure what you mean by "mismatched log messages" or "the rest can be handled by an appropriate exception message"... could you clarify please? I think all this discussion is nicely converging to the same set of required changes. 👍 |
Sure but make it opt-in. Don't enforce log capture unless a user calls for I'll say it again, in
@nicoddemus it seemed to me that @The-Compiler was implying that console printing of the log message (i.e. to a std stream) was necessary to demonstrate which log message was mismatched (i.e. different then what a test asserts using |
Thanks @Thisch for chiming in, apologies on my part for the delay, I was partially out for the holidays.
TBH I'm not sure how else we could have been more careful... we've merged a popular and mature plugin into the core, which been in use for many years (even under the name I suppose we might have asked to people to "please install pytest-catchlog because it will be part of the core in the next release" and see the feedback, but I doubt too many people accompany the mailing list or posts, and how many would have the time to actually do it. Perhaps we can start doing beta releases to gather feedback? I would love to hear ideas on how to prevent this kind of thing in the future though.
Definitely! I'm keen to release 3.4 as soon as we settle this. 😁
Agreed!
I kinda disagree here, because I think the problem is not capturing the root logger, but the default level used. Capturing the root logger just seem logical from my POV because that's the logger you get when you call
Can you elaborate why do you think it doesn't make sense in your opinion? Is it because in your vision it will limit the utility of the plugin in the first place? I think given all the problems that may rise when we capture everything, using the default level for capturing makes sense to me. Actually, just to emphasize, I think we should not set any level in any logger unless the user explicitly requests so using the
Agreed. This is fixed by writing to
I'm not a big fan... this will immediately break every pytest-3.4 user out there because nobody will have their option in this Again I don't think the main problem is which logger to capture, but the default level used. In summary, here's what I think should be done in my vision: Live Logging
Logging capture
I think "live logging" is a better term than "cli logging", in which case we should create new options as alias to the old ones, and consider the old ones deprecated:
|
in addition,
This would follow the "path of least surprise" for projects not using log-capture. |
@ederag I'm not sure. I see the output you provided a link to, and it is verbose because it is printing
Indeed this might be a problem. It is my understanding though that those projects output logging to stderr because they were not using I like the fact that logging is automatically captured (using the defaults in the new proposal) without new users having to do anything, similar to how stdout/stderr capture is also done out of the box, but I might be wrong here. EDIT: on the other hand, logging is not configured by Python by default, perhaps pytest should follow the same logic. |
@nicoddemus Yes, it is a different use case, not related to pytest.
Exactly, the application logger level should not be tampered with during the tests, |
My 2 cents: A few major problems we ran into when updating to pytest 3.3:
As you guys said, anybody that has been using pytest likely has logging setup and configured how they wanted. Merging in capturelog threw that out the window. And finally, a sample use case for |
Thanks @astraw38 for sharing your thoughts. Can you take a look at the changes proposed in #3013 (comment) and see if they are enough to improve the logging support in your POV or is there anything missing? |
The major concern I have is the default setting of log level, since you'd be modifying the root logger and affecting everything. This is more of a documentation thing, but users should be setting log levels programmatically if they want varying levels across libraries/modules (and setting And a minor feature that I'd like would be capture + livelogging. Full run logging aside, it is really nice to have the captured logs for a given test in junitxml :) |
Under the new proposal we wouldn't touch the log level of the root logger at all, unless the user explicitly asks to by passing
I see, but that is already possible today and under the new proposal, no? |
Not logging to stdout, as far as I can tell. You can get output on stdout by disabling capturing, but with capture enabled and setting various --log-cli* options, it won't output to terminal during the test. |
Oh sorry, you are right; that will be fixed when live logging writes directly to the TerminalReporter plugin then. 👍 |
Otherwise this leaks the log level information to other tests Ref: pytest-dev#3013
Finally got time to work on this proposal, #3124 is open and all comments are welcome. |
Otherwise this leaks the log level information to other tests Ref: pytest-dev#3013
The Live Logs feature currently is enabled by default and requires the user to pass
-s
to see the logs.I see two problems:
-s
feels clumsy because now all sort of outputs will come through, reducing the actual usefulness of the feature because it will be harder to see the actual logging messages.WARNING
.My proposal:
live_logs
, defaulting toFalse
.-s
to see live logs anymore.This feature was originally implemented in eisensheng/pytest-catchlog#33 but was never released to PyPI, so I assume "live logs" has seen little use in the wild.
cc @Thisch
The text was updated successfully, but these errors were encountered: