@@ -93,13 +93,17 @@ class RunTests:
9393 python_cmd : tuple [str , ...] | None
9494 randomize : bool
9595 random_seed : int | str
96- json_file : JsonFile | None
9796
98- def copy (self , ** override ):
97+ def copy (self , ** override ) -> 'RunTests' :
9998 state = dataclasses .asdict (self )
10099 state .update (override )
101100 return RunTests (** state )
102101
102+ def create_worker_runtests (self , ** override ):
103+ state = dataclasses .asdict (self )
104+ state .update (override )
105+ return WorkerRunTests (** state )
106+
103107 def get_match_tests (self , test_name ) -> FilterTuple | None :
104108 if self .match_tests_dict is not None :
105109 return self .match_tests_dict .get (test_name , None )
@@ -120,13 +124,6 @@ def iter_tests(self):
120124 else :
121125 yield from self .tests
122126
123- def as_json (self ) -> StrJSON :
124- return json .dumps (self , cls = _EncodeRunTests )
125-
126- @staticmethod
127- def from_json (worker_json : StrJSON ) -> 'RunTests' :
128- return json .loads (worker_json , object_hook = _decode_runtests )
129-
130127 def json_file_use_stdout (self ) -> bool :
131128 # Use STDOUT in two cases:
132129 #
@@ -141,9 +138,21 @@ def json_file_use_stdout(self) -> bool:
141138 )
142139
143140
141+ @dataclasses .dataclass (slots = True , frozen = True )
142+ class WorkerRunTests (RunTests ):
143+ json_file : JsonFile
144+
145+ def as_json (self ) -> StrJSON :
146+ return json .dumps (self , cls = _EncodeRunTests )
147+
148+ @staticmethod
149+ def from_json (worker_json : StrJSON ) -> 'WorkerRunTests' :
150+ return json .loads (worker_json , object_hook = _decode_runtests )
151+
152+
144153class _EncodeRunTests (json .JSONEncoder ):
145154 def default (self , o : Any ) -> dict [str , Any ]:
146- if isinstance (o , RunTests ):
155+ if isinstance (o , WorkerRunTests ):
147156 result = dataclasses .asdict (o )
148157 result ["__runtests__" ] = True
149158 return result
@@ -158,6 +167,6 @@ def _decode_runtests(data: dict[str, Any]) -> RunTests | dict[str, Any]:
158167 data ['hunt_refleak' ] = HuntRefleak (** data ['hunt_refleak' ])
159168 if data ['json_file' ]:
160169 data ['json_file' ] = JsonFile (** data ['json_file' ])
161- return RunTests (** data )
170+ return WorkerRunTests (** data )
162171 else :
163172 return data
0 commit comments