summaryrefslogtreecommitdiff
path: root/coverage/execfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r--coverage/execfile.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 42e0d96a..b2b78444 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -1,5 +1,5 @@
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
"""Execute files of Python code."""
@@ -9,6 +9,7 @@ import struct
import sys
import types
+from coverage import env
from coverage.backward import BUILTINS
from coverage.backward import PYC_MAGIC_NUMBER, imp, importlib_util_find_spec
from coverage.misc import CoverageException, ExceptionDuringRun, NoCode, NoSource, isolate_module
@@ -111,7 +112,15 @@ def run_python_module(modulename, args):
pathname = os.path.abspath(pathname)
args[0] = pathname
- run_python_file(pathname, args, package=packagename, modulename=modulename, path0="")
+ # Python 3.7.0b3 changed the behavior of the sys.path[0] entry for -m. It
+ # used to be an empty string (meaning the current directory). It changed
+ # to be the actual path to the current directory, so that os.chdir wouldn't
+ # affect the outcome.
+ if env.PYVERSION >= (3, 7, 0, 'beta', 3):
+ path0 = os.getcwd()
+ else:
+ path0 = ""
+ run_python_file(pathname, args, package=packagename, modulename=modulename, path0=path0)
def run_python_file(filename, args, package=None, modulename=None, path0=None):
@@ -128,7 +137,7 @@ def run_python_file(filename, args, package=None, modulename=None, path0=None):
function will decide on a value.
"""
- if modulename is None and sys.version_info >= (3, 3):
+ if modulename is None and env.PYVERSION >= (3, 3):
modulename = '__main__'
# Create a module to serve as __main__
@@ -255,7 +264,7 @@ def make_code_from_pyc(filename):
raise NoCode("Bad magic number in .pyc file")
date_based = True
- if sys.version_info >= (3, 7, 0, 'alpha', 4):
+ if env.PYVERSION >= (3, 7, 0, 'alpha', 4):
flags = struct.unpack('<L', fpyc.read(4))[0]
hash_based = flags & 0x01
if hash_based:
@@ -264,7 +273,7 @@ def make_code_from_pyc(filename):
if date_based:
# Skip the junk in the header that we don't need.
fpyc.read(4) # Skip the moddate.
- if sys.version_info >= (3, 3):
+ if env.PYVERSION >= (3, 3):
# 3.3 added another long to the header (size), skip it.
fpyc.read(4)