https://github.com/python/cpython/commit/8fbf10d6cfd9c69ffcc1f80fa0c5f33785197af7
commit: 8fbf10d6cfd9c69ffcc1f80fa0c5f33785197af7
branch: main
author: Mark Byrne <[email protected]>
committer: Eclips4 <[email protected]>
date: 2024-10-02T12:58:39+03:00
summary:

gh-122864: Fix a ``test_funcattrs.test___builtins__`` when executing directly 
(#124845)

Previously when executing ``test_functattrs.test___builtins__`` directly, it 
failed because the fact, that ``__builtins__`` is refers to the built-in module 
``builtins`` while it's expects a ``__builtins__.__dict__``. But when this test 
is being run from another module, then ``__builtins__`` is refers to 
``builtins.__dict__``. Now this part of the behaviour is covered.
---------

Co-authored-by: Victor Stinner <[email protected]>

files:
M Lib/test/test_funcattrs.py

diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py
index b3fc5ad42e7fde..d919d62613ea7c 100644
--- a/Lib/test/test_funcattrs.py
+++ b/Lib/test/test_funcattrs.py
@@ -98,7 +98,12 @@ def test___globals__(self):
                              (AttributeError, TypeError))
 
     def test___builtins__(self):
-        self.assertIs(self.b.__builtins__, __builtins__)
+        if __name__ == "__main__":
+            builtins_dict = __builtins__.__dict__
+        else:
+            builtins_dict = __builtins__
+
+        self.assertIs(self.b.__builtins__, builtins_dict)
         self.cannot_set_attr(self.b, '__builtins__', 2,
                              (AttributeError, TypeError))
 
@@ -108,7 +113,7 @@ def func(s): return len(s)
         ns = {}
         func2 = type(func)(func.__code__, ns)
         self.assertIs(func2.__globals__, ns)
-        self.assertIs(func2.__builtins__, __builtins__)
+        self.assertIs(func2.__builtins__, builtins_dict)
 
         # Make sure that the function actually works.
         self.assertEqual(func2("abc"), 3)

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to