https://github.com/python/cpython/commit/cceb25c5033bce5d19311d63f6943215a1a27283
commit: cceb25c5033bce5d19311d63f6943215a1a27283
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: Eclips4 <[email protected]>
date: 2024-10-02T10:36:54Z
summary:

[3.12] gh-122864: Fix a ``test_funcattrs.test___builtins__`` when executing 
directly (GH-124845) (#124885)

gh-122864: Fix a ``test_funcattrs.test___builtins__`` when executing directly 
(GH-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.
---------

(cherry picked from commit 8fbf10d6cfd9c69ffcc1f80fa0c5f33785197af7)

Co-authored-by: Mark Byrne <[email protected]>
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 35b473d5e9a0b4..7ab1b0b5f7014c 100644
--- a/Lib/test/test_funcattrs.py
+++ b/Lib/test/test_funcattrs.py
@@ -76,7 +76,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))
 
@@ -86,7 +91,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