summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
Diffstat (limited to 'coverage')
-rw-r--r--coverage/debug.py1
-rw-r--r--coverage/env.py3
-rw-r--r--coverage/execfile.py7
-rw-r--r--coverage/files.py7
4 files changed, 17 insertions, 1 deletions
diff --git a/coverage/debug.py b/coverage/debug.py
index c713978a..c516ac5b 100644
--- a/coverage/debug.py
+++ b/coverage/debug.py
@@ -215,6 +215,7 @@ def simplify(v): # pragma: debugging
def pp(v): # pragma: debugging
"""Debug helper to pretty-print data, including SimpleNamespace objects."""
+ # Might not be needed in 3.9+
pprint.pprint(simplify(v))
diff --git a/coverage/env.py b/coverage/env.py
index bb335ab3..0d4642ef 100644
--- a/coverage/env.py
+++ b/coverage/env.py
@@ -78,6 +78,9 @@ class PYBEHAVIOR(object):
# Are while-true loops optimized into absolute jumps with no loop setup?
nix_while_true = (PYVERSION >= (3, 8))
+ # Python 3.9a1 made sys.argv[0] and other reported files absolute paths.
+ report_absolute_files = (PYVERSION >= (3, 9))
+
# Coverage.py specifics.
# Are we using the C-implemented trace function?
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 5527d10a..7ac36dcf 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -13,6 +13,7 @@ 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.files import python_reported_file
from coverage.misc import CoverageException, ExceptionDuringRun, NoCode, NoSource, isolate_module
from coverage.phystokens import compile_unicode
from coverage.python import get_python_source
@@ -158,6 +159,7 @@ class PyRunner(object):
except ImportError:
pass
else:
+ try_filename = python_reported_file(try_filename)
self.spec = importlib.machinery.ModuleSpec("__main__", None, origin=try_filename)
self.spec.has_location = True
self.package = ""
@@ -167,6 +169,9 @@ class PyRunner(object):
if env.PY3:
self.loader = DummyLoader("__main__")
+ self.args[0] = python_reported_file(self.args[0])
+ self.arg0 = python_reported_file(self.arg0)
+
if self.modulename is None:
self.modulename = '__main__'
@@ -179,7 +184,7 @@ class PyRunner(object):
top_file = inspect.stack()[-1][0].f_code.co_filename
if os.path.abspath(sys.path[0]) == os.path.abspath(os.path.dirname(top_file)):
# Set sys.path correctly.
- sys.path[0] = path0
+ sys.path[0] = python_reported_file(path0)
def run(self):
"""Run the Python code!"""
diff --git a/coverage/files.py b/coverage/files.py
index dc8c248f..2836d4e5 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -172,6 +172,13 @@ def abs_file(filename):
return path
+def python_reported_file(filename):
+ """Return the string as Python would describe this file name."""
+ if env.PYBEHAVIOR.report_absolute_files:
+ filename = os.path.abspath(filename)
+ return filename
+
+
RELATIVE_DIR = None
CANONICAL_FILENAME_CACHE = None
set_relative_directory()