Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear caplog and use as context manager in test_logging #3382

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,24 +306,25 @@ def test_logging(
monkeypatch: pytest.MonkeyPatch,
):
"""Test that engine logs statements as expected"""
caplog.set_level(logging.DEBUG, logger=Engine.__module__)
# Include a callback, since most logging happens around callback events
dummy_state.callbacks = [EventCounterCallback()]

monkeypatch.setenv('ENGINE_DEBUG', '1')
engine = Engine(dummy_state, dummy_logger)
engine.run_event('INIT')
engine.close()

# Validate that we have the expected log entries
assert caplog.record_tuples == [
('composer.core.engine', 10, '[ep=0][ba=0][event=INIT]: Running event'),
('composer.core.engine', 10, '[ep=0][ba=0][event=INIT]: Running callback EventCounterCallback'),
('composer.core.engine', 10, 'Closing the engine.'),
('composer.core.engine', 10, 'Closing callback EventCounterCallback'),
('composer.core.engine', 10, 'Post-closing callback EventCounterCallback'),
('composer.core.engine', 10, 'Engine closed.'),
]
caplog.clear()
with caplog.at_level(logging.DEBUG, logger=Engine.__module__):
# Include a callback, since most logging happens around callback events
dummy_state.callbacks = [EventCounterCallback()]

monkeypatch.setenv('ENGINE_DEBUG', '1')
engine = Engine(dummy_state, dummy_logger)
engine.run_event('INIT')
engine.close()

# Validate that we have the expected log entries
assert caplog.record_tuples == [
('composer.core.engine', 10, '[ep=0][ba=0][event=INIT]: Running event'),
('composer.core.engine', 10, '[ep=0][ba=0][event=INIT]: Running callback EventCounterCallback'),
('composer.core.engine', 10, 'Closing the engine.'),
('composer.core.engine', 10, 'Closing callback EventCounterCallback'),
('composer.core.engine', 10, 'Post-closing callback EventCounterCallback'),
('composer.core.engine', 10, 'Engine closed.'),
]


def _worker():
Expand Down
Loading