Ensure that 'set_level' is undone after the end of the test. Tests the logging output themselves (affacted both by logger and handler levels).
(pytester: Pytester)
| 29 | |
| 30 | |
| 31 | def test_change_level_undo(pytester: Pytester) -> None: |
| 32 | """Ensure that 'set_level' is undone after the end of the test. |
| 33 | |
| 34 | Tests the logging output themselves (affacted both by logger and handler levels). |
| 35 | """ |
| 36 | pytester.makepyfile( |
| 37 | """ |
| 38 | import logging |
| 39 | |
| 40 | def test1(caplog): |
| 41 | caplog.set_level(logging.INFO) |
| 42 | # using + operator here so fnmatch_lines doesn't match the code in the traceback |
| 43 | logging.info('log from ' + 'test1') |
| 44 | assert 0 |
| 45 | |
| 46 | def test2(caplog): |
| 47 | # using + operator here so fnmatch_lines doesn't match the code in the traceback |
| 48 | logging.info('log from ' + 'test2') |
| 49 | assert 0 |
| 50 | """ |
| 51 | ) |
| 52 | result = pytester.runpytest() |
| 53 | result.stdout.fnmatch_lines(["*log from test1*", "*2 failed in *"]) |
| 54 | result.stdout.no_fnmatch_line("*log from test2*") |
| 55 | |
| 56 | |
| 57 | def test_change_level_undos_handler_level(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected