@@ -183,6 +183,9 @@ def load_dfk_session(request, pytestconfig, tmpd_cwd_session):
183183 this_process = psutil .Process ()
184184 start_fds = this_process .num_fds ()
185185 logger .error (f"BENC: start open fds: { start_fds } " )
186+
187+ assert threading .active_count () == 1 , "precondition: only one thread can be running before this test: " + repr (threading .enumerate ())
188+
186189 spec = importlib .util .spec_from_file_location ('' , config )
187190 module = importlib .util .module_from_spec (spec )
188191 spec .loader .exec_module (module )
@@ -212,6 +215,9 @@ def load_dfk_session(request, pytestconfig, tmpd_cwd_session):
212215 assert DataFlowKernelLoader ._dfk is None
213216 end_fds = this_process .num_fds ()
214217 logger .error (f"BENC: end open fds: { end_fds } " )
218+
219+ assert threading .active_count () == 1 , "test left threads running: " + repr (threading .enumerate ())
220+
215221 else :
216222 yield
217223
@@ -238,6 +244,7 @@ def load_dfk_local_module(request, pytestconfig, tmpd_cwd_session):
238244 logger .error (f"BENC: start open fds: { start_fds } " )
239245 logger .error (f"BENC: start threads: { threading .active_count ()} " )
240246
247+ assert threading .active_count () == 1 , "precondition: only one thread can be running before this test"
241248 local_setup = getattr (request .module , "local_setup" , None )
242249 local_teardown = getattr (request .module , "local_teardown" , None )
243250 local_config = getattr (request .module , "local_config" , None )
@@ -273,6 +280,8 @@ def load_dfk_local_module(request, pytestconfig, tmpd_cwd_session):
273280 logger .error (f"BENC: end open fds: { end_fds } (vs start { start_fds } " )
274281 logger .error (f"BENC: end threads: { threading .active_count ()} " )
275282
283+ assert threading .active_count () == 1 , "test left threads running: " + repr (threading .enumerate ())
284+
276285 else :
277286 yield
278287
0 commit comments