Skip to content

Commit

Permalink
fix: create uniq path per test
Browse files Browse the repository at this point in the history
  • Loading branch information
vgorkavenko committed Jan 23, 2025
1 parent e676ca2 commit 687cbe7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/modules/csm/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down
30 changes: 25 additions & 5 deletions tests/fork/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import time
from contextlib import contextmanager
from pathlib import Path
from typing import get_args, cast

import pytest
Expand Down Expand Up @@ -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
#
Expand Down Expand Up @@ -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],
Expand All @@ -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()
Expand Down Expand Up @@ -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']
Expand Down
3 changes: 0 additions & 3 deletions tests/fork/test_csm_oracle_cycle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import subprocess

import pytest

from src.modules.csm.csm import CSOracle
Expand All @@ -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
Expand Down

0 comments on commit 687cbe7

Please sign in to comment.