diff --git a/src/modules/csm/state.py b/src/modules/csm/state.py index 701133160..03526b523 100644 --- a/src/modules/csm/state.py +++ b/src/modules/csm/state.py @@ -8,7 +8,7 @@ from src.types import EpochNumber, ValidatorIndex from src.utils.range import sequence -from src.variables import CACHE_PATH +from src import variables logger = logging.getLogger(__name__) @@ -81,7 +81,7 @@ def commit(self) -> None: @classmethod def file(cls) -> Path: - return CACHE_PATH / Path("cache").with_suffix(cls.EXTENSION) + return variables.CACHE_PATH / Path("cache").with_suffix(cls.EXTENSION) @property def buffer(self) -> Path: diff --git a/tests/fork/conftest.py b/tests/fork/conftest.py index 7e5984a28..62af53a52 100644 --- a/tests/fork/conftest.py +++ b/tests/fork/conftest.py @@ -2,6 +2,7 @@ import subprocess import time from contextlib import contextmanager +from pathlib import Path from typing import get_args, cast import pytest @@ -84,6 +85,26 @@ def set_delay_and_sleep(monkeypatch): yield +@pytest.fixture(autouse=True) +def set_cache_path(monkeypatch, testrun_path): + with monkeypatch.context(): + monkeypatch.setattr( + variables, + "CACHE_PATH", + Path(testrun_path), + ) + logger.info(f"TESTRUN Set CACHE_PATH to {testrun_path}") + yield + + +@pytest.fixture +def testrun_path(testrun_uid): + path = f"./testrun_{testrun_uid}" + subprocess.run(['mkdir', path]) + yield path + subprocess.run(['rm', '-rf', path], check=True) + + # # Utils # @@ -174,14 +195,14 @@ def blockstamp_for_forking( @pytest.fixture() -def forked_el_client(blockstamp_for_forking: BlockStamp): +def forked_el_client(blockstamp_for_forking: BlockStamp, testrun_path: str): port = Faker().random_int(min=10000, max=20000) cli_params = [ 'anvil', '--port', str(port), '--config-out', - 'localhost.json', + f'{testrun_path}/localhost.json', '--auto-impersonate', '-f', variables.EXECUTION_CLIENT_URI[0], @@ -200,7 +221,6 @@ def forked_el_client(blockstamp_for_forking: BlockStamp): yield web3 process.terminate() process.wait() - subprocess.run(['rm', 'localhost.json'], check=True) @pytest.fixture() @@ -232,8 +252,8 @@ def _publish(self, content: bytes, name: str | None = None) -> CID: @pytest.fixture() -def accounts_from_fork(forked_el_client): - with open('localhost.json') as f: +def accounts_from_fork(forked_el_client, testrun_path): + with open(f'{testrun_path}/localhost.json') as f: data = json.load(f) addresses = data['available_accounts'] private_keys = data['private_keys'] diff --git a/tests/fork/test_csm_oracle_cycle.py b/tests/fork/test_csm_oracle_cycle.py index 92bfb0c30..c36d99d70 100644 --- a/tests/fork/test_csm_oracle_cycle.py +++ b/tests/fork/test_csm_oracle_cycle.py @@ -1,5 +1,3 @@ -import subprocess - import pytest from src.modules.csm.csm import CSOracle @@ -18,7 +16,6 @@ def hash_consensus_bin(): @pytest.fixture() def csm_module(web3: Web3): yield CSOracle(web3) - subprocess.run(['rm', 'cache.pkl'], check=True) @pytest.fixture