[Python-checkins] gh-107446: Fix test_inspect.test_class_with_method_from_other_module when ran multiple times (#107451)

kumaraditya303 webhook-mailer at python.org
Thu Aug 3 11:04:07 EDT 2023


https://github.com/python/cpython/commit/14fbd4e6b16dcbcbff448b047f7e2faa27bbedba
commit: 14fbd4e6b16dcbcbff448b047f7e2faa27bbedba
branch: main
author: Tian Gao <gaogaotiantian at hotmail.com>
committer: kumaraditya303 <kumaraditya at python.org>
date: 2023-08-03T15:04:03Z
summary:

gh-107446: Fix test_inspect.test_class_with_method_from_other_module when ran multiple times (#107451)

Co-authored-by: Kumar Aditya <kumaraditya at python.org>

files:
M Lib/test/test_inspect.py

diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 3fbfc07325553..5c31748ce2caa 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,



More information about the Python-checkins mailing list