summaryrefslogtreecommitdiff
path: root/coverage/execfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r--coverage/execfile.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 43bdc5c3..09947bcd 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -2,6 +2,14 @@
import imp, os, sys
+try:
+ # In Py 2.x, the builtins were in __builtin__
+ BUILTINS = sys.modules['__builtin__']
+except KeyError:
+ # In Py 3.x, they're in builtin
+ BUILTINS = sys.modules['builtin']
+
+
def run_python_file(filename, args):
"""Run a python file as if it were the main program on the command line.
@@ -15,7 +23,7 @@ def run_python_file(filename, args):
main_mod = imp.new_module('__main__')
sys.modules['__main__'] = main_mod
main_mod.__file__ = filename
- main_mod.__builtins__ = sys.modules['__builtin__']
+ main_mod.__builtins__ = BUILTINS
# Set sys.argv and the first path element properly.
old_argv = sys.argv