Skip to content

fix(app): avoid reconfiguring root logging in test runs to preserve caplog - #2484

Open
taran-dev4u wants to merge 3 commits into
FlexMeasures:mainfrom
taran-dev4u:fix/app-logging-config-preserve-caplog
Open

fix(app): avoid reconfiguring root logging in test runs to preserve caplog#2484
taran-dev4u wants to merge 3 commits into
FlexMeasures:mainfrom
taran-dev4u:fix/app-logging-config-preserve-caplog

Conversation

@taran-dev4u

Copy link
Copy Markdown
Contributor

Closes #2455.

create() unconditionally called configure_logging(), which executed loggingDictConfig and replaced the root logger's handlers with the default console/file handlers. When a test constructed a throwaway application (such as test_app_queues_use_custom_global_and_queue_job_timeout), this stripped the LogCaptureHandler installed by pytest's caplog fixture, causing later tests in the session with log assertions to fail with empty captures.

This adds do_configure_logging: bool = True to create(), skips configure_logging() during active pytest test execution (PYTEST_CURRENT_TEST), and sets disable_existing_loggers: False in flexmeasures_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 -q

Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Building an app in a test silently breaks pytest's caplog for every test after it

1 participant