|
1 | 1 | # mypy: disable-error-code="attr-defined"
|
2 | 2 | import logging
|
| 3 | +from typing import Iterator |
3 | 4 |
|
4 | 5 | import pytest
|
5 | 6 | from _pytest.logging import caplog_records_key
|
|
9 | 10 | sublogger = logging.getLogger(__name__ + ".baz")
|
10 | 11 |
|
11 | 12 |
|
12 |
| -@pytest.fixture |
13 |
| -def cleanup_disabled_logging(): |
| 13 | +@pytest.fixture(autouse=True) |
| 14 | +def cleanup_disabled_logging() -> Iterator[None]: |
14 | 15 | """Simple fixture that ensures that a test doesn't disable logging.
|
15 | 16 |
|
16 | 17 | This is necessary because ``logging.disable()`` is global, so a test disabling logging
|
@@ -42,7 +43,7 @@ def test_change_level(caplog):
|
42 | 43 | assert "CRITICAL" in caplog.text
|
43 | 44 |
|
44 | 45 |
|
45 |
| -def test_change_level_logging_disabled(caplog, cleanup_disabled_logging): |
| 46 | +def test_change_level_logging_disabled(caplog): |
46 | 47 | logging.disable(logging.CRITICAL)
|
47 | 48 | assert logging.root.manager.disable == logging.CRITICAL
|
48 | 49 | caplog.set_level(logging.WARNING)
|
@@ -85,9 +86,7 @@ def test2(caplog):
|
85 | 86 | result.stdout.no_fnmatch_line("*log from test2*")
|
86 | 87 |
|
87 | 88 |
|
88 |
| -def test_change_disabled_level_undo( |
89 |
| - pytester: Pytester, cleanup_disabled_logging |
90 |
| -) -> None: |
| 89 | +def test_change_disabled_level_undo(pytester: Pytester) -> None: |
91 | 90 | """Ensure that '_force_enable_logging' in 'set_level' is undone after the end of the test.
|
92 | 91 |
|
93 | 92 | Tests the logging output themselves (affected by disabled logging level).
|
@@ -159,7 +158,7 @@ def test_with_statement(caplog):
|
159 | 158 | assert "CRITICAL" in caplog.text
|
160 | 159 |
|
161 | 160 |
|
162 |
| -def test_with_statement_logging_disabled(caplog, cleanup_disabled_logging): |
| 161 | +def test_with_statement_logging_disabled(caplog): |
163 | 162 | logging.disable(logging.CRITICAL)
|
164 | 163 | assert logging.root.manager.disable == logging.CRITICAL
|
165 | 164 | with caplog.at_level(logging.WARNING):
|
@@ -197,9 +196,7 @@ def test_with_statement_logging_disabled(caplog, cleanup_disabled_logging):
|
197 | 196 | ("NOTVALIDLEVEL", logging.NOTSET),
|
198 | 197 | ],
|
199 | 198 | )
|
200 |
| -def test_force_enable_logging_level_string( |
201 |
| - caplog, cleanup_disabled_logging, level_str, expected_disable_level |
202 |
| -): |
| 199 | +def test_force_enable_logging_level_string(caplog, level_str, expected_disable_level): |
203 | 200 | """Test _force_enable_logging using a level string.
|
204 | 201 |
|
205 | 202 | ``expected_disable_level`` is one level below ``level_str`` because the disabled log level
|
|
0 commit comments