Skip to content

🧪 Add tests for log.configure options#39

Draft
rnovatorov wants to merge 3 commits intomainfrom
add-log-configure-tests-4294315772741945419
Draft

🧪 Add tests for log.configure options#39
rnovatorov wants to merge 3 commits intomainfrom
add-log-configure-tests-4294315772741945419

Conversation

@rnovatorov
Copy link
Copy Markdown
Member

🎯 What: The testing gap addressed
The global log configure function in src/enapter/log/__init__.py previously lacked dedicated unit tests. It is critical to ensure that when it alters the LOGGER's level and handlers, it behaves as expected given different input arguments.

📊 Coverage: What scenarios are now tested
The new test suite comprehensively covers:

  • Passing level=None: Ensures the logger gets a single NullHandler.
  • Passing a string level (e.g., "DEBUG"): Ensures it sets the appropriate numeric log level and attaches a StreamHandler configured with JSONFormatter.
  • Passing an integer level (e.g., logging.INFO): Same as above.
  • Passing a custom stream: Verifies that passing a specific stream like io.StringIO() properly attaches that exact stream to the generated StreamHandler.

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

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>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules bot and others added 2 commits March 17, 2026 17:30
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>
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.

1 participant