@@ -86,9 +86,9 @@ def pytest_addoption(parser: Parser) -> None:
86
86
)
87
87
parser .addoption (
88
88
"--use-zipapp" ,
89
- action = "store " ,
90
- default = None ,
91
- help = "use given pip zipapp when running pip in tests" ,
89
+ action = "store_true " ,
90
+ default = False ,
91
+ help = "use a zipapp when running pip in tests" ,
92
92
)
93
93
94
94
@@ -493,17 +493,17 @@ def with_wheel(virtualenv: VirtualEnvironment, wheel_install: Path) -> None:
493
493
494
494
class ScriptFactory (Protocol ):
495
495
def __call__ (
496
- self , tmpdir : Path , virtualenv : Optional [VirtualEnvironment ] = None , zipapp : Optional [ str ] = None
496
+ self , tmpdir : Path , virtualenv : Optional [VirtualEnvironment ] = None
497
497
) -> PipTestEnvironment :
498
498
...
499
499
500
500
501
501
@pytest .fixture (scope = "session" )
502
502
def script_factory (
503
- virtualenv_factory : Callable [[Path ], VirtualEnvironment ], deprecated_python : bool
503
+ virtualenv_factory : Callable [[Path ], VirtualEnvironment ], deprecated_python : bool , zipapp : Optional [ str ]
504
504
) -> ScriptFactory :
505
505
def factory (
506
- tmpdir : Path , virtualenv : Optional [VirtualEnvironment ] = None , zipapp : Optional [ str ] = None ,
506
+ tmpdir : Path , virtualenv : Optional [VirtualEnvironment ] = None ,
507
507
) -> PipTestEnvironment :
508
508
if virtualenv is None :
509
509
virtualenv = virtualenv_factory (tmpdir .joinpath ("venv" ))
@@ -529,6 +529,29 @@ def factory(
529
529
return factory
530
530
531
531
532
+ @pytest .fixture (scope = "session" )
533
+ def zipapp (request : pytest .FixtureRequest , tmpdir_factory : pytest .TempPathFactory ) -> Optional [str ]:
534
+ """
535
+ If the user requested for pip to be run from a zipapp, build that zipapp
536
+ and return its location. If the user didn't request a zipapp, return None.
537
+
538
+ This fixture is session scoped, so the zipapp will only be created once.
539
+ """
540
+ if not request .config .getoption ("--use-zipapp" ):
541
+ return None
542
+
543
+ temp_location = tmpdir_factory .mktemp ("zipapp" )
544
+ pyz_file = temp_location / "pip.pyz"
545
+ # What we want to do here is `pip wheel --wheel-dir temp_location <source_dir>`
546
+ # and then build a zipapp from that wheel.
547
+ # TODO: Remove hard coded file
548
+ za = "pip-22.2.dev0.pyz"
549
+ import warnings
550
+ warnings .warn (f"Copying { za } to { pyz_file } " )
551
+ shutil .copyfile (za , pyz_file )
552
+ return str (pyz_file )
553
+
554
+
532
555
@pytest .fixture
533
556
def script (
534
557
request : pytest .FixtureRequest ,
@@ -542,8 +565,7 @@ def script(
542
565
test function. The returned object is a
543
566
``tests.lib.PipTestEnvironment``.
544
567
"""
545
- zipapp = request .config .getoption ("--use-zipapp" )
546
- return script_factory (tmpdir .joinpath ("workspace" ), virtualenv , zipapp )
568
+ return script_factory (tmpdir .joinpath ("workspace" ), virtualenv )
547
569
548
570
549
571
@pytest .fixture (scope = "session" )
0 commit comments