Skip to content

Commit 3297998

Browse files
committed
fix: PyPy started making argv[0] absolute. Fixes #1426
1 parent b8cb29e commit 3297998

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGES.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ development at the same time, such as 4.5.x and 5.0.
2020
Unreleased
2121
----------
2222

23-
Nothing yet.
23+
- PyPy started reporting executed files as absolute. Coverage.py adapted,
24+
fixing `issue 1426`_.
25+
26+
.. _issue 1426: https://github.com/nedbat/coveragepy/issues/1426
27+
2428

2529

2630
.. _changes_6-4-2:

coverage/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class PYBEHAVIOR:
8585
nix_while_true = (PYVERSION >= (3, 8))
8686

8787
# CPython 3.9a1 made sys.argv[0] and other reported files absolute paths.
88-
report_absolute_files = (CPYTHON and PYVERSION >= (3, 9))
88+
report_absolute_files = ((CPYTHON or (PYPYVERSION >= (7, 3, 10))) and PYVERSION >= (3, 9))
8989

9090
# Lines after break/continue/return/raise are no longer compiled into the
9191
# bytecode. They used to be marked as missing, now they aren't executable.

tests/test_process.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,11 @@ def f2():
302302
status, out = self.run_command_status("coverage run throw.py")
303303
out2 = self.run_command("python throw.py")
304304
if env.PYPY:
305-
# Pypy has an extra frame in the traceback for some reason
305+
# PyPy has an extra frame in the traceback for some reason
306306
out2 = re_lines_text("toplevel", out2, match=False)
307+
# It also uses full paths when making files absolute
308+
if env.report_absolute_files:
309+
out2 = re.sub(r'File "' + re.escape(os.getcwd()) + ".", 'File "', out2)
307310
assert out == out2
308311

309312
# But also make sure that the output is what we expect.

0 commit comments

Comments
 (0)