Skip to content

Commit 3d522c7

Browse files
committed
wip: debug logging for patches
1 parent aaa65e8 commit 3d522c7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

coverage/control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ def start(self) -> None:
683683
if self._auto_load:
684684
self.load()
685685

686-
apply_patches(self, self.config, make_pth_file=self._make_pth_file)
686+
apply_patches(self, self.config, self._debug, make_pth_file=self._make_pth_file)
687687

688688
self._collector.start()
689689
self._started = True

coverage/patch.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,26 @@
1919
from coverage.config import CoverageConfig
2020

2121

22-
def apply_patches(cov: Coverage, config: CoverageConfig, *, make_pth_file: bool=True) -> None:
22+
def apply_patches(
23+
cov: Coverage,
24+
config: CoverageConfig,
25+
debug: TDebugCtl,
26+
*,
27+
make_pth_file: bool = True,
28+
) -> None:
2329
"""Apply invasive patches requested by `[run] patch=`."""
2430

2531
for patch in sorted(set(config.patch)):
2632
if patch == "_exit":
33+
if debug.should("patch"):
34+
debug.write("Patching _exit")
2735

2836
def make_exit_patch(
2937
old_exit: Callable[[int], NoReturn],
3038
) -> Callable[[int], NoReturn]:
3139
def coverage_os_exit_patch(status: int) -> NoReturn:
40+
if debug.should("patch"):
41+
debug.write("Using _exit patch")
3242
try:
3343
cov.save()
3444
except: # pylint: disable=bare-except
@@ -43,8 +53,13 @@ def coverage_os_exit_patch(status: int) -> NoReturn:
4353
if env.WINDOWS:
4454
raise CoverageException("patch=execv isn't supported yet on Windows.")
4555

56+
if debug.should("patch"):
57+
debug.write("Patching execv")
58+
4659
def make_execv_patch(fname: str, old_execv: Any) -> Any:
4760
def coverage_execv_patch(*args: Any, **kwargs: Any) -> Any:
61+
if debug.should("patch"):
62+
debug.write(f"Using execv patch for {fname}")
4863
try:
4964
cov.save()
5065
except: # pylint: disable=bare-except
@@ -62,9 +77,7 @@ def coverage_execv_patch(*args: Any, **kwargs: Any) -> Any:
6277
# When testing locally, we need to honor the pyc file location
6378
# or they get written to the .tox directories and pollute the
6479
# next run with a different core.
65-
if (
66-
cache_prefix := os.getenv("PYTHONPYCACHEPREFIX")
67-
) is not None:
80+
if (cache_prefix := os.getenv("PYTHONPYCACHEPREFIX")) is not None:
6881
new_env["PYTHONPYCACHEPREFIX"] = cache_prefix
6982

7083
# Without this, it fails on PyPy and Ubuntu.
@@ -78,6 +91,9 @@ def coverage_execv_patch(*args: Any, **kwargs: Any) -> Any:
7891
os.execve = make_execv_patch("execve", os.execve)
7992

8093
elif patch == "subprocess":
94+
if debug.should("patch"):
95+
debug.write("Patching subprocess")
96+
8197
if make_pth_file:
8298
pth_file = create_pth_file()
8399
assert pth_file is not None

0 commit comments

Comments
 (0)