Skip to content

Commit 1413e36

Browse files
test: convert stderr assertion to caplog for logger-based warning
fix: update docstring to reflect logging module usage
1 parent 606870d commit 1413e36

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎src/specify_cli/_agent_config.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def resolve_default_init_integration() -> str:
3535
(``SPECKIT_INTEGRATION_DEFAULT``). When it names a registered integration
3636
key, that key is returned; otherwise the hardcoded
3737
:data:`DEFAULT_INIT_INTEGRATION` (``"copilot"``) is used. An invalid value
38-
emits a warning to stderr rather than silently falling back, so operators
39-
can tell a typo from an intentional default.
38+
emits a warning through the ``logging`` module rather than silently
39+
falling back, so operators can tell a typo from an intentional default.
4040
"""
4141
override = (os.environ.get(DEFAULT_INIT_INTEGRATION_ENV_VAR) or "").strip()
4242
if not override:

‎tests/test_commands_package.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,21 @@ def test_resolve_default_init_integration_whitespace_trimmed(monkeypatch):
8181

8282

8383
def test_resolve_default_init_integration_invalid_warns_and_falls_back(
84-
monkeypatch, capsys
84+
monkeypatch, caplog
8585
):
86+
import logging
87+
8688
from specify_cli._agent_config import (
8789
DEFAULT_INIT_INTEGRATION,
8890
DEFAULT_INIT_INTEGRATION_ENV_VAR,
8991
resolve_default_init_integration,
9092
)
9193
monkeypatch.setenv(DEFAULT_INIT_INTEGRATION_ENV_VAR, "not-a-real-agent")
92-
assert resolve_default_init_integration() == DEFAULT_INIT_INTEGRATION
93-
captured = capsys.readouterr()
94-
assert "not-a-real-agent" in captured.err
95-
assert DEFAULT_INIT_INTEGRATION_ENV_VAR in captured.err
94+
with caplog.at_level(logging.WARNING):
95+
assert resolve_default_init_integration() == DEFAULT_INIT_INTEGRATION
96+
messages = [record.getMessage() for record in caplog.records]
97+
assert any("not-a-real-agent" in message for message in messages)
98+
assert any(DEFAULT_INIT_INTEGRATION_ENV_VAR in message for message in messages)
9699

97100

98101
def test_resolve_default_init_integration_re_exported_from_init():

0 commit comments

Comments
 (0)