(pytester: Pytester)
| 706 | |
| 707 | |
| 708 | def test_log_file_ini(pytester: Pytester) -> None: |
| 709 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 710 | |
| 711 | pytester.makeini( |
| 712 | """ |
| 713 | [pytest] |
| 714 | log_file={} |
| 715 | log_file_level=WARNING |
| 716 | """.format( |
| 717 | log_file |
| 718 | ) |
| 719 | ) |
| 720 | pytester.makepyfile( |
| 721 | """ |
| 722 | import pytest |
| 723 | import logging |
| 724 | def test_log_file(request): |
| 725 | plugin = request.config.pluginmanager.getplugin('logging-plugin') |
| 726 | assert plugin.log_file_handler.level == logging.WARNING |
| 727 | logging.getLogger('catchlog').info("This log message won't be shown") |
| 728 | logging.getLogger('catchlog').warning("This log message will be shown") |
| 729 | print('PASSED') |
| 730 | """ |
| 731 | ) |
| 732 | |
| 733 | result = pytester.runpytest("-s") |
| 734 | |
| 735 | # fnmatch_lines does an assertion internally |
| 736 | result.stdout.fnmatch_lines(["test_log_file_ini.py PASSED"]) |
| 737 | |
| 738 | # make sure that we get a '0' exit code for the testsuite |
| 739 | assert result.ret == 0 |
| 740 | assert os.path.isfile(log_file) |
| 741 | with open(log_file) as rfh: |
| 742 | contents = rfh.read() |
| 743 | assert "This log message will be shown" in contents |
| 744 | assert "This log message won't be shown" not in contents |
| 745 | |
| 746 | |
| 747 | def test_log_file_ini_level(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected