Conversation
Add comprehensive unit tests for `enapter.log.configure` to verify that correct logging handlers, formatting, and levels are properly configured for different arguments (`level=None`, integer and string level names, and custom streams). Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
The original PR introduced unit tests for `enapter.log.configure` which modified the global `LOGGER` state. This global mutation leaked across tests, causing `test_standalone/test_mqtt_adapter.py` assertions like `device_channel.publish_log.assert_called()` to fail in CI. This commit resolves the issue by wrapping the `test_log/test_init.py` tests with an `autouse=True` fixture that takes a snapshot of the original logger's `level` and `handlers.copy()`, and restores them after the test executes. It also explicitly imports `enapter.log` instead of relying on the parent package. Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
The `test_standalone/test_mqtt_adapter.py` unit tests relied on `await asyncio.sleep(0.02)` to wait for background tasks to process queued `Log` messages and call `device_channel.publish_log`. In CI environments (specifically Python 3.13), this tight 20ms timing was occasionally too fast, causing flaky test failures (`AssertionError: Expected 'publish_log' to have been called.`). This commit increases the sleep duration in these tests to `0.1` seconds, providing a more robust buffer for the async event loop to process the queue and trigger the mock assertions. Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
🎯 What: The testing gap addressed
The global log
configurefunction insrc/enapter/log/__init__.pypreviously lacked dedicated unit tests. It is critical to ensure that when it alters theLOGGER's level and handlers, it behaves as expected given different input arguments.📊 Coverage: What scenarios are now tested
The new test suite comprehensively covers:
level=None: Ensures the logger gets a singleNullHandler."DEBUG"): Ensures it sets the appropriate numeric log level and attaches aStreamHandlerconfigured withJSONFormatter.logging.INFO): Same as above.io.StringIO()properly attaches that exact stream to the generatedStreamHandler.✨ Result: The improvement in test coverage
We now have full safety around the module's core configuration logic, preventing regressions in future refactoring of
enapter.log.PR created automatically by Jules for task 4294315772741945419 started by @rnovatorov