From 8f01e1c4e8944f7fad295f468e4ed57a7643e048 Mon Sep 17 00:00:00 2001 From: z-bowen Date: Wed, 29 Aug 2018 15:14:17 +0200 Subject: [PATCH] Problem: `caplog` not capturing logging statements in a test Solution: Put the function execution in the `caplog` context --- tests/upsert_validator/test_validator_election.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/upsert_validator/test_validator_election.py b/tests/upsert_validator/test_validator_election.py index bd18becc..8cf63a67 100644 --- a/tests/upsert_validator/test_validator_election.py +++ b/tests/upsert_validator/test_validator_election.py @@ -156,8 +156,8 @@ def test_upsert_validator_show(caplog, ongoing_election, b, priv_validator_path, show_args = Namespace(action='show', election_id=election_id) - run_upsert_validator_show(show_args, b) - with caplog.at_level(logging.INFO): - assert caplog.records.pop().msg == \ - f'public_key={public_key}\npower={power}\nnode_id={node_id}\nstatus={status}' + run_upsert_validator_show(show_args, b) + msg = caplog.records.pop().msg + assert msg == f'public_key={public_key}\npower={power}\nnode_id={node_id}\nstatus={status}' + print("I am here")