Skip to content

Commit a57b737

Browse files
fix: restore global logger state after enapter.log.configure tests
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>
1 parent 08d14ef commit a57b737

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

tests/unit/test_log/test_init.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import io
22
import logging
33

4-
import enapter
4+
import pytest
5+
6+
import enapter.log
7+
8+
9+
@pytest.fixture(autouse=True)
10+
def reset_logger():
11+
original_level = enapter.log.LOGGER.level
12+
original_handlers = enapter.log.LOGGER.handlers.copy()
13+
yield
14+
enapter.log.LOGGER.setLevel(original_level)
15+
enapter.log.LOGGER.handlers = original_handlers
516

617

718
def test_configure_level_none():

0 commit comments

Comments
 (0)