(pytester: Pytester)
| 665 | |
| 666 | |
| 667 | def test_log_file_mode_cli(pytester: Pytester) -> None: |
| 668 | class="cm"># Default log file level |
| 669 | pytester.makepyfile( |
| 670 | class="st">""" |
| 671 | import pytest |
| 672 | import logging |
| 673 | def test_log_file(request): |
| 674 | plugin = request.config.pluginmanager.getplugin(&class="cm">#x27;logging-plugin') |
| 675 | assert plugin.log_file_handler.level == logging.WARNING |
| 676 | logging.getLogger(&class="cm">#x27;catchlogclass="st">').info("This log message won't be shown") |
| 677 | logging.getLogger(&class="cm">#x27;catchlog').warning(class="st">"This log message will be shown") |
| 678 | print(&class="cm">#x27;PASSED') |
| 679 | class="st">""" |
| 680 | ) |
| 681 | |
| 682 | log_file = str(pytester.path.joinpath(class="st">"pytest.log")) |
| 683 | |
| 684 | with open(log_file, mode=class="st">"w", encoding=class="st">"utf-8") as wfh: |
| 685 | wfh.write(class="st">"A custom header\n") |
| 686 | |
| 687 | result = pytester.runpytest( |
| 688 | class="st">"-s", |
| 689 | fclass="st">"--log-file={log_file}", |
| 690 | class="st">"--log-file-mode=a", |
| 691 | class="st">"--log-file-level=WARNING", |
| 692 | ) |
| 693 | |
| 694 | class="cm"># fnmatch_lines does an assertion internally |
| 695 | result.stdout.fnmatch_lines([class="st">"test_log_file_mode_cli.py PASSED"]) |
| 696 | |
| 697 | class="cm"># make sure that we get a class="st">'0' exit code for the testsuite |
| 698 | assert result.ret == 0 |
| 699 | assert os.path.isfile(log_file) |
| 700 | with open(log_file, encoding=class="st">"utf-8") as rfh: |
| 701 | contents = rfh.read() |
| 702 | assert class="st">"A custom header" in contents |
| 703 | assert class="st">"This log message will be shown" in contents |
| 704 | assert class="st">"This log message won&class="cm">#x27;t be shown" not in contents |
| 705 | |
| 706 | |
| 707 | def test_log_file_mode_cli_invalid(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected