(pytester: Pytester)
| 775 | |
| 776 | |
| 777 | def test_log_file_ini(pytester: Pytester) -> None: |
| 778 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 779 | |
| 780 | pytester.makeini( |
| 781 | f""" |
| 782 | [pytest] |
| 783 | log_file={log_file} |
| 784 | log_file_level=WARNING |
| 785 | """ |
| 786 | ) |
| 787 | pytester.makepyfile( |
| 788 | """ |
| 789 | import pytest |
| 790 | import logging |
| 791 | def test_log_file(request): |
| 792 | plugin = request.config.pluginmanager.getplugin('logging-plugin') |
| 793 | assert plugin.log_file_handler.level == logging.WARNING |
| 794 | logging.getLogger('catchlog').info("This log message won't be shown") |
| 795 | logging.getLogger('catchlog').warning("This log message will be shown") |
| 796 | print('PASSED') |
| 797 | """ |
| 798 | ) |
| 799 | |
| 800 | result = pytester.runpytest("-s") |
| 801 | |
| 802 | # fnmatch_lines does an assertion internally |
| 803 | result.stdout.fnmatch_lines(["test_log_file_ini.py PASSED"]) |
| 804 | |
| 805 | # make sure that we get a '0' exit code for the testsuite |
| 806 | assert result.ret == 0 |
| 807 | assert os.path.isfile(log_file) |
| 808 | with open(log_file, encoding="utf-8") as rfh: |
| 809 | contents = rfh.read() |
| 810 | assert "This log message will be shown" in contents |
| 811 | assert "This log message won't be shown" not in contents |
| 812 | |
| 813 | |
| 814 | def test_log_file_mode_ini(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected