-
Notifications
You must be signed in to change notification settings - Fork 6
Disable Logger Caching #10
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
Comments
Hi @ghickman , can you make a reproducible example please? I've tried with |
First of all: thank you for your awesome work, now I have a very convenient way to test my log system 🚀 But I faced up with same problem about |
Example: https://github.com/b0g3r/pytest-structlog-issue-example |
@ghickman Possible workaround:
|
Thanks @b0g3r! That's effectively what I ended up doing too:
@wimglenn – apologies for not supplying a reproducible example yet, @b0g3r's example is very close to mine. I'll try to get you one next week (deadlines!) to confirm my issue is the same. |
OK, I think I understand the issue now. It's a combination of two things, configuring logging at import time and enabling structlog's caching. That aspect of the global cache is actually mentioned in structlog docs https://www.structlog.org/en/stable/performance.html
Maybe it should also be mentioned that configuring the logging at import time in module global scope is somewhat an anti-pattern (see the note at the bottom of where to configure), it's usually better to configure after entering the main entry point in order for imports not to cause side-effects. However, since there is no disadvantage for pytest-structlog to also handle that case, I've released v0.3 which should cover this - please let me know if upgrading fixes the problem. Cheers! |
Version 0.3 breaks our tests. We use django and configure structlog in our settings.py file.
When we run the tests we now get this error:
|
structlog.configure()
setscache_logger_on_first_use=True
by default.With structlog==20.1.0 and pyest-structlog==0.2 I have multiple tests calling the same function and only the first one sees any logs in the event list. I think this can be fixed with
configure(…, cache_logger_on_first_use=False)
when constructing thelog
fixture.The text was updated successfully, but these errors were encountered: