bpo-35717: Fix KeyError exception raised when using enums and compile (GH-11523) (GH-11669)

https://bugs.python.org/issue17467
(cherry picked from commit 1fd06f1eca80dcbf3a916133919482a8327f3da4)

Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index b221045..fdc3dd9 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1866,6 +1866,15 @@
             REVERT_ALL = "REVERT_ALL"
             RETRY = "RETRY"
 
+    def test_empty_globals(self):
+        # bpo-35717: sys._getframe(2).f_globals['__name__'] fails with KeyError
+        # when using compile and exec because f_globals is empty
+        code = "from enum import Enum; Enum('Animal', 'ANT BEE CAT DOG')"
+        code = compile(code, "<string>", "exec")
+        global_ns = {}
+        local_ls = {}
+        exec(code, global_ns, local_ls)
+
 
 class TestOrder(unittest.TestCase):