(pytester: Pytester)
| 812 | |
| 813 | |
| 814 | def test_log_file_mode_ini(pytester: Pytester) -> None: |
| 815 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 816 | |
| 817 | pytester.makeini( |
| 818 | f""" |
| 819 | [pytest] |
| 820 | log_file={log_file} |
| 821 | log_file_mode=a |
| 822 | log_file_level=WARNING |
| 823 | """ |
| 824 | ) |
| 825 | pytester.makepyfile( |
| 826 | """ |
| 827 | import pytest |
| 828 | import logging |
| 829 | def test_log_file(request): |
| 830 | plugin = request.config.pluginmanager.getplugin('logging-plugin') |
| 831 | assert plugin.log_file_handler.level == logging.WARNING |
| 832 | logging.getLogger('catchlog').info("This log message won't be shown") |
| 833 | logging.getLogger('catchlog').warning("This log message will be shown") |
| 834 | print('PASSED') |
| 835 | """ |
| 836 | ) |
| 837 | |
| 838 | with open(log_file, mode="w", encoding="utf-8") as wfh: |
| 839 | wfh.write("A custom header\n") |
| 840 | |
| 841 | result = pytester.runpytest("-s") |
| 842 | |
| 843 | # fnmatch_lines does an assertion internally |
| 844 | result.stdout.fnmatch_lines(["test_log_file_mode_ini.py PASSED"]) |
| 845 | |
| 846 | assert result.ret == ExitCode.OK |
| 847 | assert os.path.isfile(log_file) |
| 848 | with open(log_file, encoding="utf-8") as rfh: |
| 849 | contents = rfh.read() |
| 850 | assert "A custom header" in contents |
| 851 | assert "This log message will be shown" in contents |
| 852 | assert "This log message won't be shown" not in contents |
| 853 | |
| 854 | |
| 855 | def test_log_file_ini_level(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected