Problem: A dirty test in test_utils is contaminating the test env

Solution: Added a work around to allow testing of `upsert_validator show`
Added TODOs to detail what is wrong with the broken test
Raising it as a GitHub issue to fix the bad test
This commit is contained in:
z-bowen 2018-08-29 17:33:15 +02:00
parent 3de8b7a0db
commit ba856c2044
3 changed files with 22 additions and 8 deletions

View File

@ -212,7 +212,12 @@ def run_upsert_validator_show(args, bigchain):
node_id = new_validator['node_id']
status = election.get_status(bigchain)
logger.info(f'public_key={public_key}\npower={power}\nnode_id={node_id}\nstatus={status}')
response = f'public_key={public_key}\npower={power}\nnode_id={node_id}\nstatus={status}'
logger.info(response)
# TODO: Remove this once tests/commands/test_utils.test_configure_bigchaindb_logging.py is fixed
return response
def _run_init():

View File

@ -72,6 +72,11 @@ def test_configure_bigchaindb_configures_bigchaindb():
logging.CRITICAL)
)))
def test_configure_bigchaindb_logging(log_level):
# TODO: See following comment:
# This is a dirty test. If a test *preceding* this test makes use of the logger, and then another test *after* this
# test also makes use of the logger, somehow we get logger.disabled == True, and the later test fails. We need to
# engineer this somehow to leave the test env in the same state as it finds it.
from bigchaindb.commands.utils import configure_bigchaindb
@configure_bigchaindb

View File

@ -1,7 +1,6 @@
# Copyright BigchainDB GmbH and BigchainDB contributors
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
import logging
from argparse import Namespace
import pytest
@ -144,8 +143,7 @@ def test_get_status_inconclusive(b, inconclusive_election, new_validator):
assert resp == status
@pytest.mark.dev
def test_upsert_validator_show(caplog, ongoing_election, b, priv_validator_path, user_sk, monkeypatch):
def test_upsert_validator_show(caplog, ongoing_election, b):
from bigchaindb.commands.bigchaindb import run_upsert_validator_show
election_id = ongoing_election.id
@ -157,7 +155,13 @@ def test_upsert_validator_show(caplog, ongoing_election, b, priv_validator_path,
show_args = Namespace(action='show',
election_id=election_id)
with caplog.at_level(logging.INFO):
run_upsert_validator_show(show_args, b)
msg = caplog.records.pop().msg
# TODO: Turn this back on once tests/commands/test_utils.test_configure_bigchaindb_logging.py is fixed
# with caplog.at_level(logging.INFO):
# 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}'
# TODO: Remove everything after this once tests/commands/test_utils.test_configure_bigchaindb_logging.py is fixed
msg = run_upsert_validator_show(show_args, b)
assert msg == f'public_key={public_key}\npower={power}\nnode_id={node_id}\nstatus={status}'