diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-08-03 13:07:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-03 13:07:59 (GMT) |
commit | bc2841c7a9fe2b05ef77ebdf77701188dc83b2ce (patch) | |
tree | ba6dfb5b744cfbccf4dad06e194f052a1f3c47c8 | |
parent | 84494db41902774ea6ac72e5b308b429850bbf71 (diff) | |
download | cpython-bc2841c7a9fe2b05ef77ebdf77701188dc83b2ce.zip cpython-bc2841c7a9fe2b05ef77ebdf77701188dc83b2ce.tar.gz cpython-bc2841c7a9fe2b05ef77ebdf77701188dc83b2ce.tar.bz2 |
bpo-44808: fixes test for interactive inspect getsource of a class (GH-27571)
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
(cherry picked from commit 58325971de0faf330c9c38269dae8315a0746e59)
Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
-rw-r--r-- | Lib/test/test_inspect.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 157f315..a977828 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -586,19 +586,15 @@ class TestRetrievingSourceCode(GetSourceBase): self.assertSourceEqual(mod.eggs.__code__, 12, 18) class TestGetsourceInteractive(unittest.TestCase): - def tearDown(self): - mod.ParrotDroppings.__module__ = self.mod - sys.modules['__main__'] = self.main - def test_getclasses_interactive(self): - self.main = sys.modules['__main__'] - self.mod = mod.ParrotDroppings.__module__ - class MockModule: - __file__ = None - sys.modules['__main__'] = MockModule - mod.ParrotDroppings.__module__ = '__main__' - with self.assertRaisesRegex(OSError, 'source code not available') as e: - inspect.getsource(mod.ParrotDroppings) + # bpo-44648: simulate a REPL session; + # there is no `__file__` in the __main__ module + code = "import sys, inspect; \ + assert not hasattr(sys.modules['__main__'], '__file__'); \ + A = type('A', (), {}); \ + inspect.getsource(A)" + _, _, stderr = assert_python_failure("-c", code, __isolated=True) + self.assertIn(b'OSError: source code not available', stderr) class TestGettingSourceOfToplevelFrames(GetSourceBase): fodderModule = mod |