(pytester: Pytester)
| 745 | |
| 746 | |
| 747 | def test_log_file_ini_level(pytester: Pytester) -> None: |
| 748 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 749 | |
| 750 | pytester.makeini( |
| 751 | """ |
| 752 | [pytest] |
| 753 | log_file={} |
| 754 | log_file_level = INFO |
| 755 | """.format( |
| 756 | log_file |
| 757 | ) |
| 758 | ) |
| 759 | pytester.makepyfile( |
| 760 | """ |
| 761 | import pytest |
| 762 | import logging |
| 763 | def test_log_file(request): |
| 764 | plugin = request.config.pluginmanager.getplugin('logging-plugin') |
| 765 | assert plugin.log_file_handler.level == logging.INFO |
| 766 | logging.getLogger('catchlog').debug("This log message won't be shown") |
| 767 | logging.getLogger('catchlog').info("This log message will be shown") |
| 768 | print('PASSED') |
| 769 | """ |
| 770 | ) |
| 771 | |
| 772 | result = pytester.runpytest("-s") |
| 773 | |
| 774 | # fnmatch_lines does an assertion internally |
| 775 | result.stdout.fnmatch_lines(["test_log_file_ini_level.py PASSED"]) |
| 776 | |
| 777 | # make sure that we get a '0' exit code for the testsuite |
| 778 | assert result.ret == 0 |
| 779 | assert os.path.isfile(log_file) |
| 780 | with open(log_file) as rfh: |
| 781 | contents = rfh.read() |
| 782 | assert "This log message will be shown" in contents |
| 783 | assert "This log message won't be shown" not in contents |
| 784 | |
| 785 | |
| 786 | def test_log_file_unicode(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected