Skip to content

Commit 3883efe

Browse files
committed
refactor: put pth creation with the rest of the patching
1 parent 7140b98 commit 3883efe

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

coverage/files.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
import os.path
1212
import posixpath
1313
import re
14-
import site
1514
import sys
1615
from collections.abc import Iterable
17-
from pathlib import Path
1816
from typing import Callable
1917

2018
from coverage import env
@@ -216,19 +214,6 @@ def prep_patterns(patterns: Iterable[str]) -> list[str]:
216214
return prepped
217215

218216

219-
def create_pth_file() -> Path | None:
220-
"""Create .pth file for measuring subprocesses."""
221-
for pth_dir in site.getsitepackages(): # pragma: part covered
222-
pth_file = Path(pth_dir) / f"subcover_{os.getpid()}.pth"
223-
try:
224-
pth_file.write_text("import coverage; coverage.process_startup()\n", encoding="utf-8")
225-
except OSError: # pragma: cant happen
226-
continue
227-
else:
228-
return pth_file
229-
return None # pragma: cant happen
230-
231-
232217
class TreeMatcher:
233218
"""A matcher for files in a tree.
234219

coverage/patch.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
import atexit
99
import os
10+
import site
11+
from pathlib import Path
1012
from typing import TYPE_CHECKING, Any, Callable, NoReturn
1113

1214
from coverage import env
1315
from coverage.exceptions import ConfigError, CoverageException
14-
from coverage.files import create_pth_file
1516

1617
if TYPE_CHECKING:
1718
from coverage import Coverage
@@ -87,3 +88,16 @@ def coverage_execv_patch(*args: Any, **kwargs: Any) -> Any:
8788

8889
else:
8990
raise ConfigError(f"Unknown patch {patch!r}")
91+
92+
93+
def create_pth_file() -> Path | None:
94+
"""Create .pth file for measuring subprocesses."""
95+
for pth_dir in site.getsitepackages(): # pragma: part covered
96+
pth_file = Path(pth_dir) / f"subcover_{os.getpid()}.pth"
97+
try:
98+
pth_file.write_text("import coverage; coverage.process_startup()\n", encoding="utf-8")
99+
except OSError: # pragma: cant happen
100+
continue
101+
else:
102+
return pth_file
103+
return None # pragma: cant happen

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import pytest
1919

20-
from coverage.files import set_relative_directory, create_pth_file
20+
from coverage.files import set_relative_directory
21+
from coverage.patch import create_pth_file
22+
2123

2224
# Pytest will rewrite assertions in test modules, but not elsewhere.
2325
# This tells pytest to also rewrite assertions in these files:

0 commit comments

Comments
 (0)