Skip to content

Commit 1d9e62a

Browse files
committed
wip: don't make .pth files if we already have them
1 parent 6d22489 commit 1d9e62a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

coverage/control.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ def __init__( # pylint: disable=too-many-arguments
268268
self._warn_preimported_source = check_preimported
269269
self._no_warn_slugs: set[str] = set()
270270
self._messages = messages
271+
self._patch_pth_file = True
271272

272273
# A record of all the warnings that have been issued.
273274
self._warnings: list[str] = []
@@ -678,7 +679,7 @@ def start(self) -> None:
678679
if self._auto_load:
679680
self.load()
680681

681-
apply_patches(self, self.config)
682+
apply_patches(self, self.config, pth_file=self._patch_pth_file)
682683

683684
self._collector.start()
684685
self._started = True
@@ -1432,6 +1433,7 @@ def process_startup() -> Coverage | None:
14321433
cov._warn_unimported_source = False
14331434
cov._warn_preimported_source = False
14341435
cov._auto_save = True
1436+
cov._patch_pth_file = False
14351437
cov.start()
14361438

14371439
return cov

coverage/patch.py

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

2121

22-
def apply_patches(cov: Coverage, config: CoverageConfig) -> None:
22+
def apply_patches(cov: Coverage, config: CoverageConfig, *, pth_file: bool=True) -> None:
2323
"""Apply invasive patches requested by `[run] patch=`."""
2424

2525
for patch in sorted(set(config.patch)):
@@ -78,9 +78,10 @@ def coverage_execv_patch(*args: Any, **kwargs: Any) -> Any:
7878
os.execve = make_execv_patch("execve", os.execve)
7979

8080
elif patch == "subprocess":
81-
pth_file = create_pth_file()
82-
assert pth_file is not None
83-
atexit.register(pth_file.unlink, missing_ok=True)
81+
if pth_file:
82+
pth_file = create_pth_file()
83+
assert pth_file is not None
84+
atexit.register(pth_file.unlink, missing_ok=True)
8485
assert config.config_file is not None
8586
os.environ["COVERAGE_PROCESS_START"] = config.config_file
8687

0 commit comments

Comments
 (0)