fix(app): avoid reconfiguring root logging in test runs to preserve caplog - #2484
Open
taran-dev4u wants to merge 3 commits into
Open
fix(app): avoid reconfiguring root logging in test runs to preserve caplog#2484taran-dev4u wants to merge 3 commits into
taran-dev4u wants to merge 3 commits into
Conversation
…aplog Calling create() unconditionally invoked configure_logging(), which executed loggingDictConfig and replaced the root logger handlers. When a test constructed an ad-hoc application, this stripped pytest LogCaptureHandler and broke subsequent caplog assertions across the test session. Add do_configure_logging to create(), skip configure_logging() during active pytest test execution unless explicitly requested, and set disable_existing_loggers to False in flexmeasures_logging_config. Signed-off-by: Taran Mamidala <mamidalataran6333@gmail.com>
Signed-off-by: Taran Mamidala <mamidalataran6333@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2455.
create()unconditionally calledconfigure_logging(), which executedloggingDictConfigand replaced the root logger's handlers with the default console/file handlers. When a test constructed a throwaway application (such astest_app_queues_use_custom_global_and_queue_job_timeout), this stripped theLogCaptureHandlerinstalled by pytest'scaplogfixture, causing later tests in the session with log assertions to fail with empty captures.This adds
do_configure_logging: bool = Truetocreate(), skipsconfigure_logging()during active pytest test execution (PYTEST_CURRENT_TEST), and setsdisable_existing_loggers: Falseinflexmeasures_logging_config.How to test
pytest "flexmeasures/utils/tests/test_job_utils.py::test_app_queues_use_custom_global_and_queue_job_timeout" flexmeasures/data/tests/test_utils.py -q -p no:randomly pytest flexmeasures/utils/tests/test_config_utils.py -qSign-off