Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing: add git to PATH #930

Merged
merged 7 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
import subprocess
import sys
from pathlib import Path
Expand Down Expand Up @@ -40,7 +41,9 @@ def pytest_configure(config):
config.option.markexpr = new_markexpr


def pipx_temp_env_helper(pipx_shared_dir, tmp_path, monkeypatch, request):
def pipx_temp_env_helper(
pipx_shared_dir, tmp_path, monkeypatch, request, utils_temp_dir
):
home_dir = Path(tmp_path) / "subdir" / "pipxhome"
bin_dir = Path(tmp_path) / "otherdir" / "pipxbindir"

Expand All @@ -59,7 +62,7 @@ def pipx_temp_env_helper(pipx_shared_dir, tmp_path, monkeypatch, request):
# which make tests fail (e.g. on Github ansible apps exist in /usr/bin)
monkeypatch.setenv("PATH_ORIG", str(bin_dir) + os.pathsep + os.getenv("PATH"))
monkeypatch.setenv("PATH_TEST", str(bin_dir))
monkeypatch.setenv("PATH", str(bin_dir))
monkeypatch.setenv("PATH", str(bin_dir) + os.pathsep + str(utils_temp_dir))
uranusjr marked this conversation as resolved.
Show resolved Hide resolved
# On Windows, monkeypatch pipx.commands.common._can_symlink_cache to
# indicate that constants.LOCAL_BIN_DIR cannot use symlinks, even if
# we're running as administrator and symlinks are actually possible.
Expand Down Expand Up @@ -134,8 +137,23 @@ def pipx_session_shared_dir(tmp_path_factory):
return tmp_path_factory.mktemp("session_shareddir")


@pytest.fixture(scope="session")
def utils_temp_dir(tmp_path_factory):
tmp_path = tmp_path_factory.mktemp("session_utilstempdir")
utils = ["git"]
for util in utils:
util_path = Path(shutil.which(util))
try:
(tmp_path / util_path.name).symlink_to(util_path)
except FileExistsError:
pass
return tmp_path


@pytest.fixture
def pipx_temp_env(tmp_path, monkeypatch, pipx_session_shared_dir, request):
def pipx_temp_env(
tmp_path, monkeypatch, pipx_session_shared_dir, request, utils_temp_dir
):
"""Sets up temporary paths for pipx to install into.

Shared libs are setup once per session, all other pipx dirs, constants are
Expand All @@ -144,11 +162,13 @@ def pipx_temp_env(tmp_path, monkeypatch, pipx_session_shared_dir, request):
Also adds environment variables as necessary to make pip installations
seamless.
"""
pipx_temp_env_helper(pipx_session_shared_dir, tmp_path, monkeypatch, request)
pipx_temp_env_helper(
pipx_session_shared_dir, tmp_path, monkeypatch, request, utils_temp_dir
)


@pytest.fixture
def pipx_ultra_temp_env(tmp_path, monkeypatch, request):
def pipx_ultra_temp_env(tmp_path, monkeypatch, request, utils_temp_dir):
"""Sets up temporary paths for pipx to install into.

Fully temporary environment, every test function starts as if pipx has
Expand All @@ -158,4 +178,4 @@ def pipx_ultra_temp_env(tmp_path, monkeypatch, request):
seamless.
"""
shared_dir = Path(tmp_path) / "shareddir"
pipx_temp_env_helper(shared_dir, tmp_path, monkeypatch, request)
pipx_temp_env_helper(shared_dir, tmp_path, monkeypatch, request, utils_temp_dir)
3 changes: 1 addition & 2 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ def test_install_tricky_packages(
install_package(capsys, pipx_temp_env, caplog, package_spec, package_name)


# TODO: Add git+... spec when git is in binpath of tests (Issue #303)
@pytest.mark.parametrize(
"package_name, package_spec",
[
# ("nox", "git+https://github.com/cs01/nox.git@5ea70723e9e6"),
("pycowsay", "git+https://github.com/cs01/pycowsay.git@master"),
("pylint", PKG["pylint"]["spec"]),
("nox", "https://github.com/wntrblm/nox/archive/2022.1.7.zip"),
],
Expand Down
1 change: 0 additions & 1 deletion tests/test_package_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def test_fix_package_name(package_spec_in, package_name, package_spec_out):
assert fix_package_name(package_spec_in, package_name) == package_spec_out


# TODO: Make sure git+ works with tests, correct in test_install as well
@pytest.mark.parametrize(
"package_spec_in,package_or_url_correct,valid_spec",
[
Expand Down