Repository: pypa/pip
File: tests/functional/test_install_script.py (Python)

Code before:
        "does_not_exist.py",
        "--requirements-from-script",
        "also_does_not_exist.py",
        allow_stderr_error=True,
        expect_error=True,
    )

    assert (
        "ERROR: --requirements-from-script can only be given once" in result.stderr
    ), ("multiple script did not fail as expected -- " + result.stderr)


@pytest.mark.network
def test_script_file_python_version(script: PipTestEnvironment) -> None:
    """
    Test installing from a script with an incompatible `requires-python`
    """

    other_lib_name, other_lib_version = "peppercorn", "0.6"
    script_path = script.scratch_path.joinpath("script.py")
    target_python_ver = f"{sys.version_info.major}.{sys.version_info.minor + 1}"
    script_path.write_text(
        textwrap.dedent(
            f"""\
            # /// script
            # requires-python = ">={target_python_ver}"
            # dependencies = [
            #   "INITools==0.2",
            #   "{other_lib_name}<={other_lib_version}",
            # ]
            # ///

            print("Hello world from a dummy program")
            """
        )
    )

    result = script.pip(
        "install",
        "--requirements-from-script",
        script_path,
        expect_stderr=True,
        expect_error=True,
    )

    if sys.platform == "win32":
        # Special case: result.stderr contains an extra layer of backslash
        # escaping, transform our path to match
        script_path_str = str(script_path).replace("\\", "\\\\")
    else:
        script_path_str = str(script_path)

Review comment (suggestion):
```suggestion
            # requires-python = "!={sys.version_info.major}.{sys.version_info.minor}"
```

This saves the need to do version arithmetic, which (IMO) obscures the point of the test.

Code after:


def test_script_file_python_version(script: PipTestEnvironment) -> None:
    """
    Test installing from a script with an incompatible `requires-python`
    """

    script_path = script.scratch_path.joinpath("script.py")

    script_path.write_text(
        textwrap.dedent(
            f"""\
            # /// script
            # requires-python = "!={sys.version_info.major}.{sys.version_info.minor}.*"
            # dependencies = [
            #   "INITools==0.2",
            #   "simple==1.0",
            # ]
            # ///

            print("Hello world from a dummy program")
            """
        )
    )

    result = script.pip_install_local(
        "--requirements-from-script",
        script_path,
        expect_stderr=True,
        expect_error=True,
    )

    assert "requires a different Python" in result.stderr, (
        "Script with incompatible requires-python did not fail as expected -- "
        + result.stderr
    )


def test_script_invalid_TOML(script: PipTestEnvironment) -> None:
    """
    Test installing from a script with invalid TOML in its 'script' metadata
    """

    script_path = script.scratch_path.joinpath("script.py")

    script_path.write_text(
        textwrap.dedent(
            f"""\
            # /// script
            # requires-python = "!={sys.version_info.major}.{sys.version_info.minor}.*"
            # dependencies = [