-
Notifications
You must be signed in to change notification settings - Fork 6
Structlog configuration is not restored to its previous state after test #14
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
Hmm, I wonder if we can address both this issue and the other one without regressing .. will take a look |
I forgot to link this page that recommends disabling the caching in tests: https://www.structlog.org/en/stable/testing.html
I didn't downgrade the library but commented out |
Yep, I got it, but the issue was that if |
I did some experiments. There is no way of resetting the cached logger after first use even if you use |
…since it caused a regression in #14. users should mock out their own structlog configuration in tests if necessary
Thanks for the reproducer. I've added it to the test suite in #17 This should be resolved in v0.4 |
I have noticed this unexpected behavior.
I managed to create a single test file that illustrates what is wrong:
Each test passes when executed separately, yet the last test fails if they are executed together. The reason is that here we reset the configuration:
pytest-structlog/pytest_structlog.py
Line 76 in c31f23f
The default configuration sets the
logger_factory
toPrintLoggerFactory
. Once the test is finished the whole configuration should be restored but only processors are restored. Restored processors are incompatible with thePrintLogger
object. Thus the last test fails with:I think we shouldn't reset the configuration globally. Is there a reason to do so? The code in the
structlog
distribution replaces only processors: https://github.com/hynek/structlog/blob/main/src/structlog/testing.py#L50The code with more context:
pytest-structlog/pytest_structlog.py
Lines 76 to 83 in c31f23f
The text was updated successfully, but these errors were encountered: