(pytester: Pytester)
| 663 | |
| 664 | |
| 665 | def test_log_file_cli_level(pytester: Pytester) -> None: |
| 666 | # Default log file level |
| 667 | pytester.makepyfile( |
| 668 | """ |
| 669 | import pytest |
| 670 | import logging |
| 671 | def test_log_file(request): |
| 672 | plugin = request.config.pluginmanager.getplugin('logging-plugin') |
| 673 | assert plugin.log_file_handler.level == logging.INFO |
| 674 | logging.getLogger('catchlog').debug("This log message won't be shown") |
| 675 | logging.getLogger('catchlog').info("This log message will be shown") |
| 676 | print('PASSED') |
| 677 | """ |
| 678 | ) |
| 679 | |
| 680 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 681 | |
| 682 | result = pytester.runpytest("-s", f"--log-file={log_file}", "--log-file-level=INFO") |
| 683 | |
| 684 | # fnmatch_lines does an assertion internally |
| 685 | result.stdout.fnmatch_lines(["test_log_file_cli_level.py PASSED"]) |
| 686 | |
| 687 | # make sure that we get a '0' exit code for the testsuite |
| 688 | assert result.ret == 0 |
| 689 | assert os.path.isfile(log_file) |
| 690 | with open(log_file) as rfh: |
| 691 | contents = rfh.read() |
| 692 | assert "This log message will be shown" in contents |
| 693 | assert "This log message won't be shown" not in contents |
| 694 | |
| 695 | |
| 696 | def test_log_level_not_changed_by_default(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected