From 060c9e818af90d0694ca43fb3c7cf45e24197bbb Mon Sep 17 00:00:00 2001 From: Felix Henneke Date: Fri, 4 Oct 2024 16:52:01 +0200 Subject: [PATCH] fix test monkey patching environment variables failed due to a strange config for sleep times --- tests/e2e/test_blockchain_data.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/e2e/test_blockchain_data.py b/tests/e2e/test_blockchain_data.py index 831e2f5..886c185 100644 --- a/tests/e2e/test_blockchain_data.py +++ b/tests/e2e/test_blockchain_data.py @@ -1,13 +1,29 @@ -from os import getenv +from os import getenv, environ +from unittest.mock import patch from dotenv import load_dotenv +import pytest from web3 import Web3 -from src.helpers.blockchain_data import BlockchainData load_dotenv() -def tests_get_tx_hashes_blocks(): +@pytest.fixture() +def set_env_variables(monkeypatch): + """Set `REMOVE_SOLVER_PK` to a string so that blacklisting can be called.""" + with patch.dict(environ, clear=True): + envvars = { + "CHAIN_SLEEP_TIME": "1", + } + for k, v in envvars.items(): + monkeypatch.setenv(k, v) + yield # This is the magical bit which restore the environment after + + +def tests_get_tx_hashes_blocks(set_env_variables): + # import has to happen after patching environment variable + from src.helpers.blockchain_data import BlockchainData + web3 = Web3(Web3.HTTPProvider(getenv("NODE_URL"))) blockchain = BlockchainData(web3) start_block = 20892118