(pytester: Pytester)
| 853 | |
| 854 | |
| 855 | def test_log_file_ini_level(pytester: Pytester) -> None: |
| 856 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 857 | |
| 858 | pytester.makeini( |
| 859 | f""" |
| 860 | [pytest] |
| 861 | log_file={log_file} |
| 862 | log_file_level = INFO |
| 863 | """ |
| 864 | ) |
| 865 | pytester.makepyfile( |
| 866 | """ |
| 867 | import pytest |
| 868 | import logging |
| 869 | def test_log_file(request): |
| 870 | plugin = request.config.pluginmanager.getplugin('logging-plugin') |
| 871 | assert plugin.log_file_handler.level == logging.INFO |
| 872 | logging.getLogger('catchlog').debug("This log message won't be shown") |
| 873 | logging.getLogger('catchlog').info("This log message will be shown") |
| 874 | print('PASSED') |
| 875 | """ |
| 876 | ) |
| 877 | |
| 878 | result = pytester.runpytest("-s") |
| 879 | |
| 880 | # fnmatch_lines does an assertion internally |
| 881 | result.stdout.fnmatch_lines(["test_log_file_ini_level.py PASSED"]) |
| 882 | |
| 883 | # make sure that we get a '0' exit code for the testsuite |
| 884 | assert result.ret == 0 |
| 885 | assert os.path.isfile(log_file) |
| 886 | with open(log_file, encoding="utf-8") as rfh: |
| 887 | contents = rfh.read() |
| 888 | assert "This log message will be shown" in contents |
| 889 | assert "This log message won't be shown" not in contents |
| 890 | |
| 891 | |
| 892 | def test_log_file_unicode(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected