@@ -28,19 +28,16 @@ class StateTest(Item):
2828 """Single state test case item."""
2929
3030 test_case : TestCase
31- test_dict : Dict [str , Any ]
3231
3332 def __init__ (
3433 self ,
3534 * args : Any ,
3635 test_case : TestCase ,
37- test_dict : Dict [str , Any ],
3836 ** kwargs : Any ,
3937 ) -> None :
4038 """Initialize a single test case item."""
4139 super ().__init__ (* args , ** kwargs )
4240 self .test_case = test_case
43- self .test_dict = test_dict
4441 self .add_marker (pytest .mark .fork (self .test_case .fork_name ))
4542 self .add_marker ("evm_tools" )
4643 self .add_marker ("json_state_tests" )
@@ -51,13 +48,19 @@ def __init__(
5148 if any (x .search (test_case .key ) for x in test_patterns .slow ):
5249 self .add_marker ("slow" )
5350
51+ def test_dict (self ) -> Dict [str , Any ]:
52+ """Load test from disk."""
53+ with open (self .test_case .path , "r" ) as file :
54+ loaded_file = json .load (file )
55+ return loaded_file [self .test_case .key ]
56+
5457 def runtest (self ) -> None :
5558 """
5659 Runs a single general state test.
5760 """
5861 index = self .test_case .index
5962 json_fork = self .test_case .fork_name
60- test_dict = self .test_dict
63+ test_dict = self .test_dict ()
6164
6265 env = test_dict ["env" ]
6366 try :
@@ -131,6 +134,19 @@ class StateTestFixture(Fixture, Collector):
131134 cases.
132135 """
133136
137+ _test_dict : Dict [str , Any ] | None
138+
139+ def __init__ (
140+ self ,
141+ * args : Any ,
142+ test_dict : Dict [str , Any ],
143+ ** kwargs : Any ,
144+ ) -> None :
145+ """Initialize a single blockchain test fixture from a JSON file."""
146+ super ().__init__ (* args , ** kwargs )
147+ # Save for collection purposes only, then free.
148+ self ._test_dict = test_dict
149+
134150 @classmethod
135151 def is_format (cls , test_dict : Dict [str , Any ]) -> bool :
136152 """Return true if the object can be parsed as the fixture type."""
@@ -146,10 +162,12 @@ def is_format(cls, test_dict: Dict[str, Any]) -> bool:
146162
147163 def collect (self ) -> Iterable [Item | Collector ]:
148164 """Collect state test cases inside of this fixture."""
165+ assert self ._test_dict is not None
166+ test_dict , self ._test_dict = self ._test_dict , None
149167 for test_case in read_test_case (
150168 test_file_path = self .test_file ,
151169 key = self .test_key ,
152- test = self . test_dict ,
170+ test = test_dict ,
153171 ):
154172 if test_case .fork_name not in FORKS :
155173 continue
@@ -158,5 +176,4 @@ def collect(self) -> Iterable[Item | Collector]:
158176 parent = self ,
159177 name = name ,
160178 test_case = test_case ,
161- test_dict = self .test_dict ,
162179 )
0 commit comments