Skip to content
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ test-common-wheels = [
# As required by pytest-cov.
"coverage >= 4.4",
"pytest-subket >= 0.8.1",
"keyring",
]

docs = [
Expand Down
Binary file added tests/data/pypi_packages/INITools-0.1.tar.gz
Binary file not shown.
Binary file added tests/data/pypi_packages/INITools-0.2.tar.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
59 changes: 36 additions & 23 deletions tests/functional/test_build_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

from pip._internal.utils.urls import path_to_url

from tests.lib import PipTestEnvironment, TestPipResult, create_test_package_with_setup
from tests.lib import (
PipTestEnvironment,
TestData,
TestPipResult,
create_test_package_with_setup,
)


def _create_simple_test_package(script: PipTestEnvironment, name: str) -> Path:
Expand All @@ -34,48 +39,52 @@ def _create_constraints_file(

def _run_pip_install_with_build_constraints(
script: PipTestEnvironment,
data: TestData,
project_dir: Path,
build_constraints_file: Path,
extra_args: list[str] | None = None,
expect_error: bool = False,
) -> TestPipResult:
"""Run pip install with build constraints and common arguments."""
args = [
"install",
"--no-cache-dir",
"--build-constraint",
str(build_constraints_file),
"--use-feature",
"build-constraint",
"--use-pep517",
]

if extra_args:
args.extend(extra_args)

args.append(str(project_dir))

return script.pip(*args, expect_error=expect_error)
return script.pip_install_local(
*args,
expect_error=expect_error,
build_isolation=True,
find_links=data.common_wheels,
)


def _run_pip_install_with_build_constraints_no_feature_flag(
script: PipTestEnvironment,
data: TestData,
project_dir: Path,
constraints_file: Path,
) -> TestPipResult:
"""Run pip install with build constraints but without the feature flag."""
return script.pip(
"install",
return script.pip_install_local(
"--build-constraint",
str(constraints_file),
"--use-pep517",
str(project_dir),
build_isolation=True,
find_links=data.common_wheels,
)


@pytest.mark.network
def test_build_constraints_basic_functionality_simple(
script: PipTestEnvironment, tmpdir: Path
script: PipTestEnvironment, data: TestData, tmpdir: Path
) -> None:
"""Test that build constraints options are accepted and processed."""
project_dir = _create_simple_test_package(
Expand All @@ -85,7 +94,10 @@ def test_build_constraints_basic_functionality_simple(
script=script, filename="constraints.txt", content="setuptools>=40.0.0\n"
)
result = _run_pip_install_with_build_constraints(
script=script, project_dir=project_dir, build_constraints_file=constraints_file
script=script,
data=data,
project_dir=project_dir,
build_constraints_file=constraints_file,
)
result.assert_installed(
"test-build-constraints", editable=False, without_files=["."]
Expand All @@ -94,7 +106,7 @@ def test_build_constraints_basic_functionality_simple(

@pytest.mark.network
def test_build_constraints_vs_regular_constraints_simple(
script: PipTestEnvironment, tmpdir: Path
script: PipTestEnvironment, data: TestData, tmpdir: Path
) -> None:
"""Test that build constraints and regular constraints work independently."""
project_dir = create_test_package_with_setup(
Expand Down Expand Up @@ -127,9 +139,8 @@ def test_build_constraints_vs_regular_constraints_simple(
assert "test_isolation" in result.stdout


@pytest.mark.network
def test_build_constraints_environment_isolation_simple(
script: PipTestEnvironment, tmpdir: Path
script: PipTestEnvironment, data: TestData, tmpdir: Path
) -> None:
"""Test that build constraints work correctly in isolated build environments."""
project_dir = _create_simple_test_package(script=script, name="test_env_isolation")
Expand All @@ -138,16 +149,16 @@ def test_build_constraints_environment_isolation_simple(
)
result = _run_pip_install_with_build_constraints(
script=script,
data=data,
project_dir=project_dir,
build_constraints_file=constraints_file,
extra_args=["--isolated"],
)
result.assert_installed("test-env-isolation", editable=False, without_files=["."])


@pytest.mark.network
def test_build_constraints_file_not_found(
script: PipTestEnvironment, tmpdir: Path
script: PipTestEnvironment, data: TestData, tmpdir: Path
) -> None:
"""Test behavior when build constraints file doesn't exist."""
project_dir = _create_simple_test_package(
Expand All @@ -156,6 +167,7 @@ def test_build_constraints_file_not_found(
missing_constraints = script.scratch_path / "missing_constraints.txt"
result = _run_pip_install_with_build_constraints(
script=script,
data=data,
project_dir=project_dir,
build_constraints_file=missing_constraints,
expect_error=True,
Expand All @@ -164,26 +176,27 @@ def test_build_constraints_file_not_found(
assert "No such file or directory" in result.stderr


@pytest.mark.network
def test_build_constraints_without_feature_flag(
script: PipTestEnvironment, tmpdir: Path
script: PipTestEnvironment, data: TestData, tmpdir: Path
) -> None:
"""Test that --build-constraint automatically enables the feature."""
project_dir = _create_simple_test_package(script=script, name="test_no_feature")
constraints_file = _create_constraints_file(
script=script, filename="constraints.txt", content="setuptools>=40.0.0\n"
)
result = _run_pip_install_with_build_constraints_no_feature_flag(
script=script, project_dir=project_dir, constraints_file=constraints_file
script=script,
data=data,
project_dir=project_dir,
constraints_file=constraints_file,
)
# Should succeed now that --build-constraint auto-enables the feature
assert result.returncode == 0
result.assert_installed("test-no-feature", editable=False, without_files=["."])


@pytest.mark.network
def test_constraints_dont_pass_through(
script: PipTestEnvironment, tmpdir: Path
script: PipTestEnvironment, data: TestData, tmpdir: Path
) -> None:
"""When build constraints enabled, check PIP_CONSTRAINT won't affect builds."""
project_dir = create_test_package_with_setup(
Expand All @@ -196,11 +209,11 @@ def test_constraints_dont_pass_through(
script=script, filename="constraints.txt", content="setuptools==2000\n"
)
with mock.patch.dict(os.environ, {"PIP_CONSTRAINT": path_to_url(str(constraints))}):
result = script.pip(
"install",
result = script.pip_install_local(
"--no-cache-dir",
str(project_dir),
"--use-pep517",
"--use-feature=build-constraint",
build_isolation=True,
find_links=data.common_wheels,
)
result.assert_installed("test_isolation", editable=False, without_files=["."])
21 changes: 4 additions & 17 deletions tests/functional/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,15 +888,13 @@ def test_freeze_with_requirement_option_package_repeated_multi_file(
assert result.stderr.count("is not installed") == 1


@pytest.mark.network
@pytest.mark.usefixtures("enable_user_site")
def test_freeze_user(
script: PipTestEnvironment, virtualenv: VirtualEnvironment, data: TestData
) -> None:
"""
Testing freeze with --user, first we have to install some stuff.
"""
script.pip("download", "setuptools", "wheel", "-d", data.packages)
script.pip_install_local("--find-links", data.find_links, "--user", "simple==2.0")
script.pip_install_local("--find-links", data.find_links, "simple2==3.0")
result = script.pip("freeze", "--user", expect_stderr=True)
Expand All @@ -909,14 +907,11 @@ def test_freeze_user(
assert "simple2" not in result.stdout


@pytest.mark.network
def test_freeze_path(tmpdir: Path, script: PipTestEnvironment, data: TestData) -> None:
"""
Test freeze with --path.
"""
script.pip(
"install", "--find-links", data.find_links, "--target", tmpdir, "simple==2.0"
)
script.pip_install_local("--target", tmpdir, "simple==2.0")
result = script.pip("freeze", "--path", tmpdir)
expected = textwrap.dedent(
"""\
Expand All @@ -926,7 +921,6 @@ def test_freeze_path(tmpdir: Path, script: PipTestEnvironment, data: TestData) -
_check_output(result.stdout, expected)


@pytest.mark.network
@pytest.mark.usefixtures("enable_user_site")
def test_freeze_path_exclude_user(
tmpdir: Path, script: PipTestEnvironment, data: TestData
Expand All @@ -936,9 +930,7 @@ def test_freeze_path_exclude_user(
up.
"""
script.pip_install_local("--find-links", data.find_links, "--user", "simple2")
script.pip(
"install", "--find-links", data.find_links, "--target", tmpdir, "simple==1.0"
)
script.pip_install_local("--target", tmpdir, "simple==1.0")
result = script.pip("freeze", "--user")
expected = textwrap.dedent(
"""\
Expand All @@ -955,7 +947,6 @@ def test_freeze_path_exclude_user(
_check_output(result.stdout, expected)


@pytest.mark.network
def test_freeze_path_multiple(
tmpdir: Path, script: PipTestEnvironment, data: TestData
) -> None:
Expand All @@ -966,12 +957,8 @@ def test_freeze_path_multiple(
os.mkdir(path1)
path2 = tmpdir / "path2"
os.mkdir(path2)
script.pip(
"install", "--find-links", data.find_links, "--target", path1, "simple==2.0"
)
script.pip(
"install", "--find-links", data.find_links, "--target", path2, "simple2==3.0"
)
script.pip_install_local("--target", path1, "simple==2.0")
script.pip_install_local("--target", path2, "simple2==3.0")
result = script.pip("freeze", "--path", path1)
expected = textwrap.dedent(
"""\
Expand Down
Loading