fix: fix LOGFIRE_IGNORE_NO_CONFIG to prevent warning from LogFireConf…#1379
fix: fix LOGFIRE_IGNORE_NO_CONFIG to prevent warning from LogFireConf…#1379alexmojaki merged 6 commits intopydantic:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
LucasSantos27
left a comment
There was a problem hiding this comment.
tip: instead of creating a new commit, you can run git commit --amend to add to the same commit
76d857a to
f2200da
Compare
LucasSantos27
left a comment
There was a problem hiding this comment.
small fixes, good job!
logfire/_internal/config.py
Outdated
| ignore_no_config_env = os.getenv('LOGFIRE_IGNORE_NO_CONFIG') | ||
| ignore_no_config = (ignore_no_config_env == '1') or self.ignore_no_config |
There was a problem hiding this comment.
| ignore_no_config_env = os.getenv('LOGFIRE_IGNORE_NO_CONFIG') | |
| ignore_no_config = (ignore_no_config_env == '1') or self.ignore_no_config | |
| ignore_no_config_env = os.getenv('LOGFIRE_IGNORE_NO_CONFIG', '') | |
| ignore_no_config = ignore_no_config_env.lower() in ('1', 'true', 't') or self.ignore_no_config |
tests/test_logfire.py
Outdated
| with warnings.catch_warnings(record=True) as warning_list: | ||
| warnings.simplefilter('always') | ||
| config.warn_if_not_initialized('Should not warn with env var') | ||
|
|
||
| logfire_warnings = [w for w in warning_list if issubclass(w.category, LogfireNotConfiguredWarning)] | ||
| assert len(logfire_warnings) == 0 |
There was a problem hiding this comment.
| with warnings.catch_warnings(record=True) as warning_list: | |
| warnings.simplefilter('always') | |
| config.warn_if_not_initialized('Should not warn with env var') | |
| logfire_warnings = [w for w in warning_list if issubclass(w.category, LogfireNotConfiguredWarning)] | |
| assert len(logfire_warnings) == 0 | |
| config.warn_if_not_initialized('Should not warn with env var') |
This is enough, if there was a warning pytest would raise an error.
tests/test_logfire.py
Outdated
| with warnings.catch_warnings(record=True) as warning_list: | ||
| warnings.simplefilter('always') | ||
|
|
||
| logfire_warnings = [w for w in warning_list if issubclass(w.category, LogfireNotConfiguredWarning)] | ||
| assert len(logfire_warnings) == 0 |
There was a problem hiding this comment.
again, no need for all this to check for a lack of warnings, but you haven't even got anything here that might emit a warning
tests/test_logfire.py
Outdated
| logfire_warnings = [w for w in warnings_list if issubclass(w.category, LogfireNotConfiguredWarning)] | ||
| assert len(logfire_warnings) == 1 |
There was a problem hiding this comment.
| logfire_warnings = [w for w in warnings_list if issubclass(w.category, LogfireNotConfiguredWarning)] | |
| assert len(logfire_warnings) == 1 | |
| assert len(warnings_list) == 1 |
if there's a different kind of warning, pytest will raise an error, since you have pytest.warns(LogfireNotConfiguredWarning).
There was a problem hiding this comment.
Thank you for the review. I have updated the code to include these changes.
|
Thanks! |
This PR introduces a fix for the issue described in #1331