From bd53c7a88ccf81c81d86cb00f033b4553d872dfa Mon Sep 17 00:00:00 2001 From: antazoey Date: Tue, 2 Jul 2024 15:06:54 -0500 Subject: [PATCH] fix: create data dir in clean method (#2167) --- src/ape_node/provider.py | 5 +++-- tests/functional/test_project.py | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ape_node/provider.py b/src/ape_node/provider.py index 5398942697..1d1e29b801 100644 --- a/src/ape_node/provider.py +++ b/src/ape_node/provider.py @@ -111,7 +111,6 @@ def __init__( self._data_dir = data_dir self._hostname = hostname self._port = port - self._data_dir.mkdir(exist_ok=True, parents=True) self.is_running = False self._auto_disconnect = auto_disconnect @@ -140,7 +139,6 @@ def __init__( bal_dict = {"balance": str(initial_balance)} alloc = {a: bal_dict for a in addresses} genesis = create_genesis_data(alloc, chain_id) - self._data_dir.mkdir(parents=True, exist_ok=True) initialize_chain(genesis, self.data_dir) super().__init__(geth_kwargs) @@ -209,6 +207,9 @@ def _clean(self): if self._data_dir.is_dir(): shutil.rmtree(self._data_dir) + # dir must exist when initializing chain. + self._data_dir.mkdir(parents=True, exist_ok=True) + def wait(self, *args, **kwargs): if self.proc is None: return diff --git a/tests/functional/test_project.py b/tests/functional/test_project.py index ed057a2d8b..bb27e08ba5 100644 --- a/tests/functional/test_project.py +++ b/tests/functional/test_project.py @@ -779,7 +779,10 @@ def clean(): ): actual = pm.sources.lookup(closest) expected = nested_source_b - assert actual == expected, f"Failed to lookup {closest}" + + # Using stem in case it returns `Contract.__mock__`, which is + # added / removed as part of other tests (running x-dist). + assert actual.stem == expected.stem, f"Failed to lookup {closest}" finally: clean()