0
0
mirror of https://github.com/python/cpython.git synced 2024-11-21 12:59:38 +01:00

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 <vstinner@python.org>
This commit is contained in:
Mark Byrne 2024-10-02 11:58:39 +02:00 committed by GitHub
parent 6737333ac5
commit 8fbf10d6cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -98,7 +98,12 @@ class FunctionPropertiesTest(FuncAttrsTest):
(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 @@ class FunctionPropertiesTest(FuncAttrsTest):
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)