Skip to content

Commit a57668e

Browse files
committed
Add an option to the test suite to specify a zipapp to test
1 parent f66b3e8 commit a57668e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

tests/conftest.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def pytest_addoption(parser: Parser) -> None:
8484
default=None,
8585
help="use given proxy in session network tests",
8686
)
87+
parser.addoption(
88+
"--use-zipapp",
89+
action="store",
90+
default=None,
91+
help="use given pip zipapp when running pip in tests",
92+
)
8793

8894

8995
def pytest_collection_modifyitems(config: Config, items: List[pytest.Function]) -> None:
@@ -487,7 +493,7 @@ def with_wheel(virtualenv: VirtualEnvironment, wheel_install: Path) -> None:
487493

488494
class ScriptFactory(Protocol):
489495
def __call__(
490-
self, tmpdir: Path, virtualenv: Optional[VirtualEnvironment] = None
496+
self, tmpdir: Path, virtualenv: Optional[VirtualEnvironment] = None, zipapp: Optional[str] = None
491497
) -> PipTestEnvironment:
492498
...
493499

@@ -497,7 +503,7 @@ def script_factory(
497503
virtualenv_factory: Callable[[Path], VirtualEnvironment], deprecated_python: bool
498504
) -> ScriptFactory:
499505
def factory(
500-
tmpdir: Path, virtualenv: Optional[VirtualEnvironment] = None
506+
tmpdir: Path, virtualenv: Optional[VirtualEnvironment] = None, zipapp: Optional[str] = None,
501507
) -> PipTestEnvironment:
502508
if virtualenv is None:
503509
virtualenv = virtualenv_factory(tmpdir.joinpath("venv"))
@@ -516,13 +522,16 @@ def factory(
516522
assert_no_temp=True,
517523
# Deprecated python versions produce an extra deprecation warning
518524
pip_expect_warning=deprecated_python,
525+
# Tell the Test Environment if we want to run pip via a zipapp
526+
zipapp=zipapp,
519527
)
520528

521529
return factory
522530

523531

524532
@pytest.fixture
525533
def script(
534+
request: pytest.FixtureRequest,
526535
tmpdir: Path,
527536
virtualenv: VirtualEnvironment,
528537
script_factory: ScriptFactory,
@@ -533,7 +542,8 @@ def script(
533542
test function. The returned object is a
534543
``tests.lib.PipTestEnvironment``.
535544
"""
536-
return script_factory(tmpdir.joinpath("workspace"), virtualenv)
545+
zipapp = request.config.getoption("--use-zipapp")
546+
return script_factory(tmpdir.joinpath("workspace"), virtualenv, zipapp)
537547

538548

539549
@pytest.fixture(scope="session")

tests/lib/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ def __init__(
507507
*args: Any,
508508
virtualenv: VirtualEnvironment,
509509
pip_expect_warning: bool = False,
510+
zipapp: Optional[str] = None,
510511
**kwargs: Any,
511512
) -> None:
512513
# Store paths related to the virtual environment
@@ -553,6 +554,9 @@ def __init__(
553554
# (useful for Python version deprecation)
554555
self.pip_expect_warning = pip_expect_warning
555556

557+
# The name of an (optional) zipapp to use when running pip
558+
self.zipapp = zipapp
559+
556560
# Call the TestFileEnvironment __init__
557561
super().__init__(base_path, *args, **kwargs)
558562

@@ -698,7 +702,10 @@ def pip(
698702
__tracebackhide__ = True
699703
if self.pip_expect_warning:
700704
kwargs["allow_stderr_warning"] = True
701-
if use_module:
705+
if self.zipapp:
706+
exe = "python"
707+
args = (self.zipapp, ) + args
708+
elif use_module:
702709
exe = "python"
703710
args = ("-m", "pip") + args
704711
else:

0 commit comments

Comments
 (0)