Skip to content

Commit 2edfc76

Browse files
committed
add test
1 parent 511865d commit 2edfc76

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Lib/test/test_inspect.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,15 @@ def test_getmodule(self):
493493
# Check filename override
494494
self.assertEqual(inspect.getmodule(None, modfile), mod)
495495

496+
def test_getmodule_file_not_found(self):
497+
# See bpo-45406
498+
def _getabsfile(obj, _filename):
499+
raise FileNotFoundError('bad file')
500+
with unittest.mock.patch('inspect.getabsfile', _getabsfile):
501+
f = inspect.currentframe()
502+
self.assertIsNone(inspect.getmodule(f))
503+
inspect.getouterframes(f) # smoke test
504+
496505
def test_getframeinfo_get_first_line(self):
497506
frame_info = inspect.getframeinfo(self.fodderModule.fr, 50)
498507
self.assertEqual(frame_info.code_context[0], "# line 1\n")

0 commit comments

Comments
 (0)