@@ -91,13 +91,17 @@ class RunTests:
9191 python_cmd : tuple [str , ...] | None
9292 randomize : bool
9393 random_seed : int | str
94- json_file : JsonFile | None
9594
96- def copy (self , ** override ):
95+ def copy (self , ** override ) -> 'RunTests' :
9796 state = dataclasses .asdict (self )
9897 state .update (override )
9998 return RunTests (** state )
10099
100+ def create_worker_runtests (self , ** override ):
101+ state = dataclasses .asdict (self )
102+ state .update (override )
103+ return WorkerRunTests (** state )
104+
101105 def get_match_tests (self , test_name ) -> FilterTuple | None :
102106 if self .match_tests_dict is not None :
103107 return self .match_tests_dict .get (test_name , None )
@@ -118,13 +122,6 @@ def iter_tests(self):
118122 else :
119123 yield from self .tests
120124
121- def as_json (self ) -> StrJSON :
122- return json .dumps (self , cls = _EncodeRunTests )
123-
124- @staticmethod
125- def from_json (worker_json : StrJSON ) -> 'RunTests' :
126- return json .loads (worker_json , object_hook = _decode_runtests )
127-
128125 def json_file_use_stdout (self ) -> bool :
129126 # Use STDOUT in two cases:
130127 #
@@ -139,9 +136,21 @@ def json_file_use_stdout(self) -> bool:
139136 )
140137
141138
139+ @dataclasses .dataclass (slots = True , frozen = True )
140+ class WorkerRunTests (RunTests ):
141+ json_file : JsonFile
142+
143+ def as_json (self ) -> StrJSON :
144+ return json .dumps (self , cls = _EncodeRunTests )
145+
146+ @staticmethod
147+ def from_json (worker_json : StrJSON ) -> 'WorkerRunTests' :
148+ return json .loads (worker_json , object_hook = _decode_runtests )
149+
150+
142151class _EncodeRunTests (json .JSONEncoder ):
143152 def default (self , o : Any ) -> dict [str , Any ]:
144- if isinstance (o , RunTests ):
153+ if isinstance (o , WorkerRunTests ):
145154 result = dataclasses .asdict (o )
146155 result ["__runtests__" ] = True
147156 return result
@@ -156,6 +165,6 @@ def _decode_runtests(data: dict[str, Any]) -> RunTests | dict[str, Any]:
156165 data ['hunt_refleak' ] = HuntRefleak (** data ['hunt_refleak' ])
157166 if data ['json_file' ]:
158167 data ['json_file' ] = JsonFile (** data ['json_file' ])
159- return RunTests (** data )
168+ return WorkerRunTests (** data )
160169 else :
161170 return data
0 commit comments