11# @Test suite for source code analysis and marker extraction, TEST_ANA_1, test, [IMPL_LNK_1, IMPL_ONE_1, IMPL_MRST_1]
22import json
3- import logging
43from pathlib import Path
54
65import pytest
@@ -144,9 +143,8 @@ def test_analyse_oneline_needs(
144143 assert cnt_comments == result ["num_comments" ]
145144
146145
147- def test_oneline_parser_warning_is_logged (tmp_path , caplog ):
148- """Test that oneline parser warnings are logged to the console."""
149-
146+ def test_oneline_parser_warnings_are_collected (tmp_path ):
147+ """Test that oneline parser warnings are collected for later output."""
150148 src_dir = TEST_DIR / "data" / "oneline_comment_default"
151149 src_paths = [src_dir / "default_oneliners.c" ]
152150
@@ -159,27 +157,11 @@ def test_oneline_parser_warning_is_logged(tmp_path, caplog):
159157 oneline_comment_style = ONELINE_COMMENT_STYLE_DEFAULT ,
160158 )
161159
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
160+ src_analyse = SourceAnalyse (src_analyse_config )
161+ src_analyse .run ()
162+
163+ # Verify that warnings were collected
164+ assert len (src_analyse .oneline_warnings ) == 1
165+ warning = src_analyse .oneline_warnings [0 ]
166+ assert "too_many_fields" in warning .sub_type
167+ assert warning .lineno == 17
0 commit comments