[3.12] Fix test_importlib.test_side_effect_import() (GH-104840) (#104842)

Fix test_importlib.test_side_effect_import() (GH-104840)

Wait until the thread spawn by the import completes to avoid dangling
threads. With this fix, the following command no longer fails:

./python -m test --fail-env-changed test_importlib -m test_side_effect_import -F -j20
(cherry picked from commit 426950993f)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2023-05-24 17:36:13 -07:00 committed by GitHub
parent a064233886
commit 51eb009cef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -238,6 +238,7 @@ class ThreadedImportTests(unittest.TestCase):
self.addCleanup(forget, TESTFN) self.addCleanup(forget, TESTFN)
self.addCleanup(rmtree, '__pycache__') self.addCleanup(rmtree, '__pycache__')
importlib.invalidate_caches() importlib.invalidate_caches()
with threading_helper.wait_threads_exit():
__import__(TESTFN) __import__(TESTFN)
del sys.modules[TESTFN] del sys.modules[TESTFN]