Make virtualenv/script fixture factories
@@ -272,16 +272,23 @@ def virtualenv_template(request, tmpdir_factory, pip_src,
yield venv
+@pytest.fixture(scope="session")
+def virtualenv_factory(virtualenv_template):
+ def factory(tmpdir):
+ return VirtualEnvironment(tmpdir, virtualenv_template)
+
+ return factory
+
+
@pytest.fixture
-def virtualenv(virtualenv_template, tmpdir, isolate):
+def virtualenv(virtualenv_factory, tmpdir):
"""
Return a virtual environment which is unique to each test function
invocation created inside of a sub directory of the test function's
temporary directory. The returned object is a
``tests.lib.venv.VirtualEnvironment`` object.
"""
- venv_location = tmpdir.joinpath("workspace", "venv")
- yield VirtualEnvironment(venv_location, virtualenv_template)
+ yield virtualenv_factory(tmpdir.joinpath("workspace", "venv"))
@pytest.fixture
@@ -289,17 +296,14 @@ def with_wheel(virtualenv, wheel_install):
install_egg_link(virtualenv, 'wheel', wheel_install)
-@pytest.fixture
-def script(tmpdir, virtualenv, deprecated_python):
- """
- Return a PipTestEnvironment which is unique to each test function and
- will execute all commands inside of the unique virtual environment for this
- test function. The returned object is a
- ``tests.lib.scripttest.PipTestEnvironment``.
- """
+@pytest.fixture(scope="session")
+def script_factory(virtualenv_factory, deprecated_python):
+ def factory(tmpdir, virtualenv=None):
+ if virtualenv is None:
+ virtualenv = virtualenv_factory(tmpdir.joinpath("venv"))
return PipTestEnvironment(
# The base location for our test environment
- tmpdir.joinpath("workspace"),
+ tmpdir,
# Tell the Test Environment where our virtualenv is located
virtualenv=virtualenv,
@@ -319,6 +323,19 @@ def script(tmpdir, virtualenv, deprecated_python):
pip_expect_warning=deprecated_python,
)
+ return factory
+
+
+@pytest.fixture
+def script(tmpdir, virtualenv, script_factory):
+ """
+ Return a PipTestEnvironment which is unique to each test function and
+ will execute all commands inside of the unique virtual environment for this
+ test function. The returned object is a
+ ``tests.lib.scripttest.PipTestEnvironment``.
+ """
+ return script_factory(tmpdir.joinpath("workspace"), virtualenv)
+
@pytest.fixture(scope="session")
def common_wheels():
@@ -359,7 +376,7 @@ def in_memory_pip():
return InMemoryPip()
-@pytest.fixture
+@pytest.fixture(scope="session")
def deprecated_python():
"""Used to indicate whether pip deprecated this python version"""
return sys.version_info[:2] in [(2, 7)]
