8000 [3.12] gh-122864: Fix a ``test_funcattrs.test___builtins__`` when exe… · python/cpython@cceb25c · GitHub
[go: up one dir, main page]

Skip to content

Commit cceb25c

Browse files
miss-islingtonmbyrnepr2vstinner
authored
[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 8fbf10d) Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 72bbebd commit cceb25c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/test/test_funcattrs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ def test___globals__(self):
7676
(AttributeError, TypeError))
7777

7878
def test___builtins__(self):
79-
self.assertIs(self.b.__builtins__, __builtins__)
79+
if __name__ == "__main__":
80+
builtins_dict = __builtins__.__dict__
81+
else:
82+
builtins_dict = __builtins__
83+
84+
self.assertIs(self.b.__builtins__, builtins_dict)
8085
self.cannot_set_attr(self.b, '__builtins__', 2,
8186
(AttributeError, TypeError))
8287

@@ -86,7 +91,7 @@ def func(s): return len(s)
8691
ns = {}
8792
func2 = type(func)(func.__code__, ns)
8893
self.assertIs(func2.__globals__, ns)
89-
self.assertIs(func2.__builtins__, __builtins__)
94+
self.assertIs(func2.__builtins__, builtins_dict)
9095

9196
# Make sure that the function actually works.
9297
self.assertEqual(func2("abc"), 3)

0 commit comments

Comments
 (0)
0