Skip to content

Commit 949cbdb

Browse files
committed
fix(unit_test): prevent logging from raising exceptions after tests
pytest's capsys just closes the stdout when done with tests. there are issues tracking this problem, see pytest-dev/pytest#5577 . but we adds a handler which redirect the logging messages to stdout. so, once pytest finishes testing, exceptions are raised when writing logging messages, like ``` 22:37:20 File "/usr/local/lib/python3.10/logging/__init__.py", line 1101, in emit 22:37:20 stream.write(msg + self.terminator) 22:37:20 ValueError: I/O operation on closed file. ``` so, in this change, `logging.raiseExceptions` is disabled when pytest's session finishes. Fixes scylladb#6000 Signed-off-by: Kefu Chai <[email protected]>
1 parent 4215637 commit 949cbdb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

unit_tests/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,14 @@ def fixture_params(request: pytest.FixtureRequest):
142142
@pytest.fixture(scope='function', autouse=True)
143143
def fixture_cleanup_continuous_events_registry():
144144
ContinuousEventsRegistry().cleanup_registry()
145+
146+
147+
def pytest_sessionfinish():
148+
# pytest's capsys is enabled by default, see
149+
# https://docs.pytest.org/en/7.1.x/how-to/capture-stdout-stderr.html.
150+
# but pytest closes its internal stream for capturing the stdout and
151+
# stderr, so we are not able to write the logger anymore once the test
152+
# session finishes. see https://github.com/pytest-dev/pytest/issues/5577,
153+
# to silence the warnings, let's just prevent logging from raising
154+
# exceptions.
155+
logging.raiseExceptions = False

0 commit comments

Comments
 (0)