@@ -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 )
@@ -217,6 +220,8 @@ def load_dfk_session(request, pytestconfig, tmpd_cwd_session):
217220        logger .error (f"BENC: end open fds: { end_fds }   (vs { start_fds }   at start)" )
218221        assert  start_fds  ==  end_fds , "number of open fds changed across test run" 
219222
223+         assert  threading .active_count () ==  1 , "test left threads running: "  +  repr (threading .enumerate ())
224+ 
220225    else :
221226        yield 
222227
@@ -243,6 +248,7 @@ def load_dfk_local_module(request, pytestconfig, tmpd_cwd_session):
243248        logger .error (f"BENC: start open fds: { start_fds }  " )
244249        logger .error (f"BENC: start threads: { threading .active_count ()}  " )
245250
251+         assert  threading .active_count () ==  1 , "precondition: only one thread can be running before this test" 
246252        local_setup  =  getattr (request .module , "local_setup" , None )
247253        local_teardown  =  getattr (request .module , "local_teardown" , None )
248254        local_config  =  getattr (request .module , "local_config" , None )
@@ -285,6 +291,8 @@ def load_dfk_local_module(request, pytestconfig, tmpd_cwd_session):
285291            os .system (f"ls -l /proc/{ os .getpid ()}  /fd" )
286292            pytest .fail ("BENC: number of open fds increased across test" )
287293
294+         assert  threading .active_count () ==  1 , "test left threads running: "  +  repr (threading .enumerate ())
295+ 
288296    else :
289297        yield 
290298
0 commit comments