1414from typing import TYPE_CHECKING
1515
1616import pytest
17+ from _pytest .recwarn import WarningsRecorder
1718
1819from pylint import checkers
1920from pylint .interfaces import HIGH
@@ -88,16 +89,12 @@ def test_template_option_non_existing(linter) -> None:
8889 """
8990 output = StringIO ()
9091 linter .reporter .out = output
91- linter .config .msg_template = (
92- "{path}:{line}:{a_new_option}:({a_second_new_option:03d})"
93- )
92+ linter .config .msg_template = "{path}:{line}:{categ}:({a_second_new_option:03d})"
9493 linter .open ()
9594 with pytest .warns (UserWarning ) as records :
9695 linter .set_current_module ("my_mod" )
9796 assert len (records ) == 2
98- assert (
99- "Don't recognize the argument 'a_new_option'" in records [0 ].message .args [0 ]
100- )
97+ assert "Don't recognize the argument 'categ'" in records [0 ].message .args [0 ]
10198 assert (
10299 "Don't recognize the argument 'a_second_new_option'"
103100 in records [1 ].message .args [0 ]
@@ -113,7 +110,24 @@ def test_template_option_non_existing(linter) -> None:
113110 assert out_lines [2 ] == "my_mod:2::()"
114111
115112
116- def test_deprecation_set_output (recwarn ):
113+ def test_template_option_with_header (linter : PyLinter ) -> None :
114+ output = StringIO ()
115+ linter .reporter .out = output
116+ linter .config .msg_template = '{{ "Category": "{category}" }}'
117+ linter .open ()
118+ linter .set_current_module ("my_mod" )
119+
120+ linter .add_message ("C0301" , line = 1 , args = (1 , 2 ))
121+ linter .add_message (
122+ "line-too-long" , line = 2 , end_lineno = 2 , end_col_offset = 4 , args = (3 , 4 )
123+ )
124+
125+ out_lines = output .getvalue ().split ("\n " )
126+ assert out_lines [1 ] == '{ "Category": "convention" }'
127+ assert out_lines [2 ] == '{ "Category": "convention" }'
128+
129+
130+ def test_deprecation_set_output (recwarn : WarningsRecorder ) -> None :
117131 """TODO remove in 3.0."""
118132 reporter = BaseReporter ()
119133 # noinspection PyDeprecation
0 commit comments