(pytester: Pytester)
| 239 | |
| 240 | |
| 241 | def test_caplog_captures_despite_exception(pytester: Pytester) -> None: |
| 242 | pytester.makepyfile( |
| 243 | """ |
| 244 | import pytest |
| 245 | import logging |
| 246 | def test_log_level_override(request, caplog): |
| 247 | logger = logging.getLogger('catchlog') |
| 248 | plugin = request.config.pluginmanager.getplugin('logging-plugin') |
| 249 | assert plugin.log_level == logging.WARNING |
| 250 | |
| 251 | logger.error("ERROR message " + "will be shown") |
| 252 | |
| 253 | with caplog.at_level(logging.DEBUG, logger.name): |
| 254 | logger.debug("DEBUG message " + "won't be shown") |
| 255 | raise Exception() |
| 256 | """ |
| 257 | ) |
| 258 | pytester.makeini( |
| 259 | """ |
| 260 | [pytest] |
| 261 | log_level=WARNING |
| 262 | """ |
| 263 | ) |
| 264 | |
| 265 | result = pytester.runpytest() |
| 266 | result.stdout.fnmatch_lines(["*ERROR message will be shown*"]) |
| 267 | result.stdout.no_fnmatch_line("*DEBUG message won't be shown*") |
| 268 | assert result.ret == 1 |
| 269 | |
| 270 | |
| 271 | def test_log_report_captures_according_to_config_option_upon_failure( |
nothing calls this directly
no test coverage detected