(pytester: Pytester)
| 56 | |
| 57 | |
| 58 | def test_root_logger_affected(pytester: Pytester) -> None: |
| 59 | pytester.makepyfile( |
| 60 | """ |
| 61 | import logging |
| 62 | logger = logging.getLogger() |
| 63 | |
| 64 | def test_foo(): |
| 65 | logger.info('info text ' + 'going to logger') |
| 66 | logger.warning('warning text ' + 'going to logger') |
| 67 | logger.error('error text ' + 'going to logger') |
| 68 | |
| 69 | assert 0 |
| 70 | """ |
| 71 | ) |
| 72 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 73 | result = pytester.runpytest("--log-level=ERROR", "--log-file=pytest.log") |
| 74 | assert result.ret == 1 |
| 75 | |
| 76 | # The capture log calls in the stdout section only contain the |
| 77 | # logger.error msg, because of --log-level=ERROR. |
| 78 | result.stdout.fnmatch_lines(["*error text going to logger*"]) |
| 79 | stdout = result.stdout.str() |
| 80 | assert "warning text going to logger" not in stdout |
| 81 | assert "info text going to logger" not in stdout |
| 82 | |
| 83 | # The log file should only contain the error log messages and |
| 84 | # not the warning or info ones, because the root logger is set to |
| 85 | # ERROR using --log-level=ERROR. |
| 86 | assert os.path.isfile(log_file) |
| 87 | with open(log_file, encoding="utf-8") as rfh: |
| 88 | contents = rfh.read() |
| 89 | assert "info text going to logger" not in contents |
| 90 | assert "warning text going to logger" not in contents |
| 91 | assert "error text going to logger" in contents |
| 92 | |
| 93 | |
| 94 | def test_log_cli_level_log_level_interaction(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected