@@ -111,6 +111,10 @@ def init_hail(run_config):
111111context = pytest .StashKey [Literal ['burn_in' , 'benchmark' ]]()
112112
113113
114+ def prune (kvs : dict ) -> dict :
115+ return {k : v for k , v in kvs .items () if v is not None }
116+
117+
114118@pytest .hookimpl (tryfirst = True )
115119def pytest_runtest_protocol (item , nextitem ):
116120 run_config = item .session .config .run_config
@@ -184,14 +188,16 @@ def pytest_pyfunc_call(pyfuncitem):
184188
185189 is_burn_in = s [context ] == 'burn_in'
186190
187- s [runs ].append ({
188- 'iteration' : s [iteration ],
189- 'time' : time ,
190- 'is_burn_in' : is_burn_in ,
191- 'timed_out' : timed_out ,
192- 'failure' : traceback ,
193- 'task_memory' : get_peak_task_memory (Env .hc ()._log ),
194- })
191+ s [runs ].append (
192+ prune ({
193+ 'iteration' : s [iteration ],
194+ 'time' : time ,
195+ 'is_burn_in' : is_burn_in ,
196+ 'timed_out' : timed_out ,
197+ 'failure' : traceback ,
198+ 'task_memory' : get_peak_task_memory (Env .hc ()._log ),
199+ })
200+ )
195201
196202 logging .info (f'{ "(burn in) " if is_burn_in else "" } iteration { s [iteration ]} , time: { time } s' )
197203
@@ -210,30 +216,30 @@ def open_file_or_stdout(file):
210216
211217@pytest .hookimpl
212218def pytest_sessionfinish (session ):
213- if not session .config .option .collectonly :
219+ if hasattr ( session , 'items' ) and len ( session . items ) > 0 and not session .config .option .collectonly :
214220 run_config = session .config .run_config
215221
216222 meta = {
217223 'uname' : platform .uname ()._asdict (),
218224 'version' : hl .__version__ ,
219- ** ({ 'batch_id' : batch } if ( batch := os .getenv ('HAIL_BATCH_ID' )) else {} ),
220- ** ({ 'job_id' : job } if ( job := os .getenv ('HAIL_JOB_ID' )) else {} ),
221- ** ({ 'trial' : trial } if ( trial := os .getenv ('BENCHMARK_TRIAL_ID' )) else {} ),
225+ 'batch_id' : os .getenv ('HAIL_BATCH_ID' ),
226+ 'job_id' : os .getenv ('HAIL_JOB_ID' ),
227+ 'trial' : os .getenv ('BENCHMARK_TRIAL_ID' ),
222228 }
223229
224230 now = datetime .now (timezone .utc ).isoformat ()
225231 with open_file_or_stdout (run_config .output ) as out :
226232 for item in session .items :
227233 path , _ , name = item .location
228234 json .dump (
229- {
235+ prune ( {
230236 'path' : path ,
231237 'name' : name ,
232238 ** meta ,
233239 'start' : item .stash [start ],
234240 'end' : item .stash .get (end , now ),
235241 'runs' : item .stash [runs ],
236- },
242+ }) ,
237243 out ,
238244 )
239245 out .write ('\n ' )
0 commit comments