diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 3fbfc073255532..5c31748ce2caac 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -990,6 +990,9 @@ def f(self): with DirsOnSysPath(tempdir): import inspect_actual self.assertIn("correct", inspect.getsource(inspect_actual.A)) + # Remove the module from sys.modules to force it to be reloaded. + # This is necessary when the test is run multiple times. + sys.modules.pop("inspect_actual") @unittest.skipIf( support.is_emscripten or support.is_wasi,