(pytester: Pytester)
| 732 | |
| 733 | |
| 734 | def test_log_file_cli_level(pytester: Pytester) -> None: |
| 735 | # Default log file level |
| 736 | pytester.makepyfile( |
| 737 | """ |
| 738 | import pytest |
| 739 | import logging |
| 740 | def test_log_file(request): |
| 741 | plugin = request.config.pluginmanager.getplugin('logging-plugin') |
| 742 | assert plugin.log_file_handler.level == logging.INFO |
| 743 | logging.getLogger('catchlog').debug("This log message won't be shown") |
| 744 | logging.getLogger('catchlog').info("This log message will be shown") |
| 745 | print('PASSED') |
| 746 | """ |
| 747 | ) |
| 748 | |
| 749 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 750 | |
| 751 | result = pytester.runpytest("-s", f"--log-file={log_file}", "--log-file-level=INFO") |
| 752 | |
| 753 | # fnmatch_lines does an assertion internally |
| 754 | result.stdout.fnmatch_lines(["test_log_file_cli_level.py PASSED"]) |
| 755 | |
| 756 | # make sure that we get a '0' exit code for the testsuite |
| 757 | assert result.ret == 0 |
| 758 | assert os.path.isfile(log_file) |
| 759 | with open(log_file, encoding="utf-8") as rfh: |
| 760 | contents = rfh.read() |
| 761 | assert "This log message will be shown" in contents |
| 762 | assert "This log message won't be shown" not in contents |
| 763 | |
| 764 | |
| 765 | def test_log_level_not_changed_by_default(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected