Skip to content

Commit ae68e00

Browse files
committed
Reset logging handlers after logging tests.
See pytest-dev/pytest#5743 for the details, and explanation of the fix.
1 parent 62a5692 commit ae68e00

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/test_log.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import mex.log
22
import mex.state
33
import logging
4+
import pytest
45
from itertools import chain
56

67
# It's important to del your State before attempting to
78
# read capsys.readouterr(), because that will close sys.stdout,
89
# and State will want to do some debug logging before it closes.
910

11+
mex_logger = logging.getLogger('mex')
12+
13+
@pytest.fixture(autouse=True)
14+
def ensure_logging_framework_not_altered():
15+
"""
16+
Resets the handlers on mex_logger after a test.
17+
See https://github.com/pytest-dev/pytest/issues/5743 for why.
18+
"""
19+
before_handlers = list(mex_logger.handlers)
20+
yield
21+
mex_logger.handlers = before_handlers
22+
1023
LOGNAMES = [
1124
'online',
1225
'macros',

0 commit comments

Comments
 (0)