(pytester: Pytester)
| 630 | |
| 631 | |
| 632 | def test_log_file_cli(pytester: Pytester) -> None: |
| 633 | # Default log file level |
| 634 | pytester.makepyfile( |
| 635 | """ |
| 636 | import pytest |
| 637 | import logging |
| 638 | def test_log_file(request): |
| 639 | plugin = request.config.pluginmanager.getplugin('logging-plugin') |
| 640 | assert plugin.log_file_handler.level == logging.WARNING |
| 641 | logging.getLogger('catchlog').info("This log message won't be shown") |
| 642 | logging.getLogger('catchlog').warning("This log message will be shown") |
| 643 | print('PASSED') |
| 644 | """ |
| 645 | ) |
| 646 | |
| 647 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 648 | |
| 649 | result = pytester.runpytest( |
| 650 | "-s", f"--log-file={log_file}", "--log-file-level=WARNING" |
| 651 | ) |
| 652 | |
| 653 | # fnmatch_lines does an assertion internally |
| 654 | result.stdout.fnmatch_lines(["test_log_file_cli.py PASSED"]) |
| 655 | |
| 656 | # make sure that we get a '0' exit code for the testsuite |
| 657 | assert result.ret == 0 |
| 658 | assert os.path.isfile(log_file) |
| 659 | with open(log_file) as rfh: |
| 660 | contents = rfh.read() |
| 661 | assert "This log message will be shown" in contents |
| 662 | assert "This log message won't be shown" not in contents |
| 663 | |
| 664 | |
| 665 | def test_log_file_cli_level(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected