@@ -1180,50 +1180,42 @@ def target():
11801180 assert (thread .ident , thread .name ) == results .get (timeout = 1 )
11811181
11821182
1183- def test_get_current_thread_meta_bad_running_thread ( ):
1183+ def get_current_thread_meta_patched ( ** patch_kwargs ):
11841184 results = Queue (maxsize = 1 )
11851185
11861186 def target ():
1187- with mock .patch ("threading.current_thread" , side_effect = [ "fake thread" ] ):
1187+ with mock .patch ("threading.current_thread" , ** patch_kwargs ):
11881188 results .put (get_current_thread_meta ())
11891189
11901190 thread = threading .Thread (target = target )
11911191 thread .start ()
11921192 thread .join ()
1193+ return results .get (timeout = 1 )
1194+
11931195
1196+ def test_get_current_thread_meta_bad_running_thread ():
11941197 main_thread = threading .main_thread ()
1195- assert (main_thread .ident , main_thread .name ) == results .get (timeout = 1 )
1198+ assert (
1199+ main_thread .ident ,
1200+ main_thread .name ,
1201+ ) == get_current_thread_meta_patched (side_effect = ["fake thread" ])
11961202
11971203
11981204def test_get_current_thread_meta_main_thread ():
1199- results = Queue (maxsize = 1 )
1200-
1201- def target ():
1202- # mock that somehow the current thread doesn't exist
1203- with mock .patch ("threading.current_thread" , side_effect = [None ]):
1204- results .put (get_current_thread_meta ())
1205-
12061205 main_thread = threading .main_thread ()
1207-
1208- thread = threading . Thread ( target = target )
1209- thread . start ()
1210- thread . join ()
1211- assert ( main_thread . ident , main_thread . name ) == results . get ( timeout = 1 )
1206+ # mock that somehow the current thread doesn't exist
1207+ assert (
1208+ main_thread . ident ,
1209+ main_thread . name ,
1210+ ) == get_current_thread_meta_patched ( side_effect = [ None ] )
12121211
12131212
12141213def test_get_current_thread_meta_failed_to_get_main_thread ():
1215- results = Queue (maxsize = 1 )
1216-
1217- def target ():
1218- with mock .patch ("threading.current_thread" , return_value = "fake thread" ):
1219- results .put (get_current_thread_meta ())
1220-
12211214 main_thread = threading .main_thread ()
1222-
1223- thread = threading .Thread (target = target )
1224- thread .start ()
1225- thread .join ()
1226- assert (main_thread .ident , main_thread .name ) == results .get (timeout = 1 )
1215+ assert (
1216+ main_thread .ident ,
1217+ main_thread .name ,
1218+ ) == get_current_thread_meta_patched (return_value = "fake thread" )
12271219
12281220
12291221@pytest .mark .parametrize (
0 commit comments