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