Skip to content

Commit 468f612

Browse files
authored
test: Don't include coverage in test env unless needed (#13716)
We don't want coverage to be imported for every Python process spawned unless we're collecting coverage. I checked and even after importing pip._internal.commands.install, importing coverage afterwards still takes 10ms which is nontrivial.
1 parent ee5b186 commit 468f612

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

tests/conftest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,13 @@ def virtualenv_template(
512512
# detects changed files.
513513
venv.site.joinpath("easy-install.pth").touch()
514514

515-
# Install coverage and pth file for executing it in any spawned processes
516-
# in this virtual environment.
517-
install_pth_link(venv, "coverage", coverage_install)
518-
# zz prefix ensures the file is after easy-install.pth.
519-
with open(venv.site / "zz-coverage-helper.pth", "a") as f:
520-
f.write("import coverage; coverage.process_startup()")
515+
if request.config.getoption("--cov"):
516+
# Install coverage and pth file for executing it in any spawned processes
517+
# in this virtual environment.
518+
install_pth_link(venv, "coverage", coverage_install)
519+
# zz prefix ensures the file is after easy-install.pth.
520+
with open(venv.site / "zz-coverage-helper.pth", "a") as f:
521+
f.write("import coverage; coverage.process_startup()")
521522

522523
# Drop (non-relocatable) launchers.
523524
for exe in os.listdir(venv.bin):

tests/functional/test_inspect.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def test_inspect_basic(simple_script: PipTestEnvironment) -> None:
2929
"""
3030
result = simple_script.pip("inspect")
3131
report = json.loads(result.stdout)
32-
installed = report["installed"]
33-
assert len(installed) == 5
34-
installed_by_name = {i["metadata"]["name"]: i for i in installed}
32+
installed_by_name = {i["metadata"]["name"]: i for i in report["installed"]}
33+
# Coverage is only installed if test coverage is being collected.
34+
installed_by_name.pop("coverage", None)
35+
assert len(installed_by_name) == 4
3536
assert installed_by_name.keys() == {
3637
"pip",
3738
"setuptools",
3839
"wheel",
39-
"coverage",
4040
"simplewheel",
4141
}
4242
assert installed_by_name["simplewheel"]["metadata"]["version"] == "1.0"

0 commit comments

Comments
 (0)