MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_log_cli_auto_enable

Function test_log_cli_auto_enable

testing/logging/test_reporting.py:589–629  ·  view source on GitHub ↗

Check that live logs are enabled if --log-level or --log-cli-level is passed on the CLI. It should not be auto enabled if the same configs are set on the INI file.

(pytester: Pytester, cli_args: str)

Source from the content-addressed store, hash-verified

587 ["", "--log-level=WARNING", "--log-file-level=WARNING", "--log-cli-level=WARNING"],
588)
589def test_log_cli_auto_enable(pytester: Pytester, cli_args: str) -> None:
590 """Check that live logs are enabled if --log-level or --log-cli-level is passed on the CLI.
591 It should not be auto enabled if the same configs are set on the INI file.
592 """
593 pytester.makepyfile(
594 """
595 import logging
596
597 def test_log_1():
598 logging.info("log message from test_log_1 not to be shown")
599 logging.warning("log message from test_log_1")
600
601 """
602 )
603 pytester.makeini(
604 """
605 [pytest]
606 log_level=INFO
607 log_cli_level=INFO
608 """
609 )
610
611 result = pytester.runpytest(cli_args)
612 stdout = result.stdout.str()
613 if cli_args == "--log-cli-level=WARNING":
614 result.stdout.fnmatch_lines(
615 [
616 "*::test_log_1 ",
617 "*-- live log call --*",
618 "*WARNING*log message from test_log_1*",
619 "PASSED *100%*",
620 "=* 1 passed in *=",
621 ]
622 )
623 assert "INFO" not in stdout
624 else:
625 result.stdout.fnmatch_lines(
626 ["*test_log_cli_auto_enable*100%*", "=* 1 passed in *="]
627 )
628 assert "INFO" not in stdout
629 assert "WARNING" not in stdout
630
631
632def test_log_file_cli(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 5

strMethod · 0.80
fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
makeiniMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected