From a0f0814fb6425f35f780dbfa1d047032923d0629 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sat, 29 Jul 2023 16:19:48 -0700 Subject: [PATCH 1/4] Fix test_inspect under --forever --- Lib/inspect.py | 2 +- Lib/test/test_inspect.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index c8211833dd0831..0302a548e57da3 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1131,7 +1131,7 @@ def findsource(object): else: lines = linecache.getlines(file) if not lines: - raise OSError('could not get source code') + raise OSError(f'could not get source code {module}, {object}, {file}') if ismodule(object): return lines, 0 diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 3fbfc073255532..f6c4ab74728748 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -990,6 +990,11 @@ def f(self): with DirsOnSysPath(tempdir): import inspect_actual self.assertIn("correct", inspect.getsource(inspect_actual.A)) + # --forever will run this test multiple times, each time the test + # executes, we create a different temporary directory, and the old + # one is removed. So we need to remove the module from sys.modules + # to force it to be reloaded. + sys.modules.pop("inspect_actual") @unittest.skipIf( support.is_emscripten or support.is_wasi, From 7e532703a0c0ff208cda366f05c712fc10cd4c52 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sat, 29 Jul 2023 16:25:47 -0700 Subject: [PATCH 2/4] Remove debug code --- Lib/inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 0302a548e57da3..e79dbe2a65091b 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1131,7 +1131,7 @@ def findsource(object): else: lines = linecache.getlines(file) if not lines: - raise OSError(f'could not get source code {module}, {object}, {file}') + raise OSError(f'could not get source code') if ismodule(object): return lines, 0 From 85b9f7c06580785a0e1f533ada1c10a328153160 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sat, 29 Jul 2023 16:26:16 -0700 Subject: [PATCH 3/4] Oops, left something there --- Lib/inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index e79dbe2a65091b..c8211833dd0831 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1131,7 +1131,7 @@ def findsource(object): else: lines = linecache.getlines(file) if not lines: - raise OSError(f'could not get source code') + raise OSError('could not get source code') if ismodule(object): return lines, 0 From a17c5f06b844fd42b0576c70698f1b096a492557 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Thu, 3 Aug 2023 20:05:29 +0530 Subject: [PATCH 4/4] Update Lib/test/test_inspect.py --- Lib/test/test_inspect.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index f6c4ab74728748..5c31748ce2caac 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -990,10 +990,8 @@ def f(self): with DirsOnSysPath(tempdir): import inspect_actual self.assertIn("correct", inspect.getsource(inspect_actual.A)) - # --forever will run this test multiple times, each time the test - # executes, we create a different temporary directory, and the old - # one is removed. So we need to remove the module from sys.modules - # to force it to be reloaded. + # 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(