@@ -211,6 +211,90 @@ def task_example(produces=Path("out.txt")):
211211 assert "INFO:hello from live log" in result .stdout
212212
213213
214+ def test_log_cli_level_from_config_does_not_enable_live_logging (tmp_path ):
215+ source = """
216+ import logging
217+
218+ logger = logging.getLogger(__name__)
219+
220+ def task_example():
221+ logger.info("hello from live log")
222+ """
223+ tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
224+ tmp_path .joinpath ("pyproject.toml" ).write_text (
225+ textwrap .dedent (
226+ """
227+ [tool.pytask.ini_options]
228+ log_cli = false
229+ log_cli_level = "INFO"
230+ log_cli_format = "%(levelname)s:%(message)s"
231+ """
232+ )
233+ )
234+
235+ result = run_in_subprocess (("pytask" , tmp_path .as_posix ()), cwd = tmp_path )
236+
237+ assert result .exit_code == ExitCode .OK
238+ assert "INFO:hello from live log" not in result .stdout
239+
240+
241+ @pytest .mark .parametrize (
242+ ("destination_args" , "expected_destination_output" ),
243+ [
244+ (
245+ (
246+ "--log-cli" ,
247+ "--log-cli-level=INFO" ,
248+ "--log-cli-format=%(levelname)s:%(message)s" ,
249+ ),
250+ "INFO:hello from destination-specific log" ,
251+ ),
252+ (
253+ (
254+ "--log-file=build.log" ,
255+ "--log-file-level=INFO" ,
256+ "--log-file-format=%(levelname)s:%(message)s" ,
257+ ),
258+ None ,
259+ ),
260+ ],
261+ ids = ["live-log" , "log-file" ],
262+ )
263+ def test_destination_specific_levels_do_not_affect_failure_report (
264+ tmp_path , destination_args , expected_destination_output
265+ ):
266+ source = """
267+ import logging
268+
269+ logger = logging.getLogger(__name__)
270+
271+ def task_example():
272+ logger.info("hello from destination-specific log")
273+ raise Exception("boom")
274+ """
275+ tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
276+
277+ result = run_in_subprocess (
278+ (
279+ "pytask" ,
280+ tmp_path .as_posix (),
281+ "--show-capture=log" ,
282+ * destination_args ,
283+ ),
284+ cwd = tmp_path ,
285+ )
286+
287+ assert result .exit_code == ExitCode .FAILED
288+ assert "Captured log" not in result .stdout
289+ if expected_destination_output is not None :
290+ assert expected_destination_output in result .stdout
291+ else :
292+ assert (
293+ tmp_path .joinpath ("build.log" ).read_text ()
294+ == "INFO:hello from destination-specific log\n "
295+ )
296+
297+
214298@pytest .mark .parametrize (
215299 ("amount" , "unit" , "short_label" , "expectation" , "expected" ),
216300 [
0 commit comments