Skip to content

Commit c5f90a4

Browse files
committed
🔧 Improve logging for oneline parser warnings in tests
1 parent d9b1de8 commit c5f90a4

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

‎tests/test_analyse.py‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# @Test suite for source code analysis and marker extraction, TEST_ANA_1, test, [IMPL_LNK_1, IMPL_ONE_1, IMPL_MRST_1]
22
import json
3+
import logging
34
from pathlib import Path
45

56
import pytest
@@ -145,6 +146,7 @@ def test_analyse_oneline_needs(
145146

146147
def test_oneline_parser_warning_is_logged(tmp_path, caplog):
147148
"""Test that oneline parser warnings are logged to the console."""
149+
148150
src_dir = TEST_DIR / "data" / "oneline_comment_default"
149151
src_paths = [src_dir / "default_oneliners.c"]
150152

@@ -157,14 +159,27 @@ def test_oneline_parser_warning_is_logged(tmp_path, caplog):
157159
oneline_comment_style=ONELINE_COMMENT_STYLE_DEFAULT,
158160
)
159161

160-
with caplog.at_level("WARNING", logger="sphinx_codelinks.analyse.analyse"):
161-
src_analyse = SourceAnalyse(src_analyse_config)
162-
src_analyse.run()
163-
164-
# Verify that warnings were collected
165-
assert len(src_analyse.oneline_warnings) == 1
166-
167-
# Verify that the warning was logged
168-
assert len(caplog.records) == 1
169-
assert "Oneline parser warning" in caplog.records[0].message
170-
assert "too_many_fields" in caplog.records[0].message
162+
# Ensure the logger propagates to root so caplog can capture it
163+
analyse_logger = logging.getLogger("sphinx_codelinks.analyse.analyse")
164+
original_propagate = analyse_logger.propagate
165+
analyse_logger.propagate = True
166+
167+
try:
168+
with caplog.at_level(
169+
logging.WARNING, logger="sphinx_codelinks.analyse.analyse"
170+
):
171+
src_analyse = SourceAnalyse(src_analyse_config)
172+
src_analyse.run()
173+
174+
# Verify that warnings were collected
175+
assert len(src_analyse.oneline_warnings) == 1
176+
177+
# Verify that the warning was logged
178+
warning_records = [
179+
r for r in caplog.records if "Oneline parser warning" in r.message
180+
]
181+
assert len(warning_records) >= 1
182+
assert "too_many_fields" in warning_records[0].message
183+
finally:
184+
# Restore original propagate setting
185+
analyse_logger.propagate = original_propagate

0 commit comments

Comments
 (0)