Skip to content

Commit 33b53e4

Browse files
committed
test: restore global logging state in configure_logging test
configure_logging() applies logging.conf, which mutates process-global logging state (replaces the pyensembl logger's NullHandler with a live console handler and reconfigures root). Snapshot and restore that state in test_configure_logging_preserves_existing_loggers so it doesn't leak a console handler into sibling tests running in the same worker. Claude-Session: https://claude.ai/code/session_016pKPSmCAts4cacC3CQ9qsL
1 parent 21d1751 commit 33b53e4

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

tests/test_shell.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,24 @@ def test_import_does_not_reconfigure_root_logger():
123123

124124

125125
def test_configure_logging_preserves_existing_loggers():
126-
created_before = logging.getLogger("test_configure_logging_preexisting")
127-
created_before.disabled = False
128-
configure_logging()
129-
# The CLI entrypoint applies logging.conf, but with
130-
# disable_existing_loggers=False so it leaves other loggers alone.
131-
assert created_before.disabled is False
132-
# pyensembl's own logger should be wired up to a handler for CLI output.
133-
assert logging.getLogger("pyensembl").handlers
126+
# configure_logging() applies logging.conf, which mutates process-global
127+
# logging state (root + pyensembl loggers). Snapshot and restore it so this
128+
# test doesn't leak a live console handler into sibling tests.
129+
root = logging.getLogger()
130+
pyensembl_logger = logging.getLogger("pyensembl")
131+
saved_root_handlers = root.handlers[:]
132+
saved_root_level = root.level
133+
saved_pyensembl_handlers = pyensembl_logger.handlers[:]
134+
try:
135+
created_before = logging.getLogger("test_configure_logging_preexisting")
136+
created_before.disabled = False
137+
configure_logging()
138+
# The CLI entrypoint applies logging.conf, but with
139+
# disable_existing_loggers=False so it leaves other loggers alone.
140+
assert created_before.disabled is False
141+
# pyensembl's own logger should be wired up to a handler for CLI output.
142+
assert pyensembl_logger.handlers
143+
finally:
144+
root.handlers[:] = saved_root_handlers
145+
root.level = saved_root_level
146+
pyensembl_logger.handlers[:] = saved_pyensembl_handlers

0 commit comments

Comments
 (0)