summaryrefslogtreecommitdiff
path: root/setuptools/tests/fixtures.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/tests/fixtures.py')
-rw-r--r--setuptools/tests/fixtures.py102
1 files changed, 84 insertions, 18 deletions
diff --git a/setuptools/tests/fixtures.py b/setuptools/tests/fixtures.py
index a5a172e0..25ab49fd 100644
--- a/setuptools/tests/fixtures.py
+++ b/setuptools/tests/fixtures.py
@@ -1,11 +1,13 @@
+import os
import contextlib
import sys
-import shutil
import subprocess
+from pathlib import Path
import pytest
+import path
-from . import contexts
+from . import contexts, environment
@pytest.fixture
@@ -28,22 +30,6 @@ def tmpdir_cwd(tmpdir):
yield orig
-@pytest.fixture
-def tmp_src(request, tmp_path):
- """Make a copy of the source dir under `$tmp/src`.
-
- This fixture is useful whenever it's necessary to run `setup.py`
- or `pip install` against the source directory when there's no
- control over the number of simultaneous invocations. Such
- concurrent runs create and delete directories with the same names
- under the target directory and so they influence each other's runs
- when they are not being executed sequentially.
- """
- tmp_src_path = tmp_path / 'src'
- shutil.copytree(request.config.rootdir, tmp_src_path)
- return tmp_src_path
-
-
@pytest.fixture(autouse=True, scope="session")
def workaround_xdist_376(request):
"""
@@ -72,3 +58,83 @@ def sample_project(tmp_path):
except Exception:
pytest.skip("Unable to clone sampleproject")
return tmp_path / 'sampleproject'
+
+
+# sdist and wheel artifacts should be stable across a round of tests
+# so we can build them once per session and use the files as "readonly"
+
+
+@pytest.fixture(scope="session")
+def setuptools_sdist(tmp_path_factory, request):
+ if os.getenv("PRE_BUILT_SETUPTOOLS_SDIST"):
+ return Path(os.getenv("PRE_BUILT_SETUPTOOLS_SDIST")).resolve()
+
+ with contexts.session_locked_tmp_dir(
+ request, tmp_path_factory, "sdist_build") as tmp:
+ dist = next(tmp.glob("*.tar.gz"), None)
+ if dist:
+ return dist
+
+ subprocess.check_call([
+ sys.executable, "-m", "build", "--sdist",
+ "--outdir", str(tmp), str(request.config.rootdir)
+ ])
+ return next(tmp.glob("*.tar.gz"))
+
+
+@pytest.fixture(scope="session")
+def setuptools_wheel(tmp_path_factory, request):
+ if os.getenv("PRE_BUILT_SETUPTOOLS_WHEEL"):
+ return Path(os.getenv("PRE_BUILT_SETUPTOOLS_WHEEL")).resolve()
+
+ with contexts.session_locked_tmp_dir(
+ request, tmp_path_factory, "wheel_build") as tmp:
+ dist = next(tmp.glob("*.whl"), None)
+ if dist:
+ return dist
+
+ subprocess.check_call([
+ sys.executable, "-m", "build", "--wheel",
+ "--outdir", str(tmp) , str(request.config.rootdir)
+ ])
+ return next(tmp.glob("*.whl"))
+
+
+@pytest.fixture
+def venv(tmp_path, setuptools_wheel):
+ """Virtual env with the version of setuptools under test installed"""
+ env = environment.VirtualEnv()
+ env.root = path.Path(tmp_path / 'venv')
+ env.req = str(setuptools_wheel)
+ # In some environments (eg. downstream distro packaging),
+ # where tox isn't used to run tests and PYTHONPATH is set to point to
+ # a specific setuptools codebase, PYTHONPATH will leak into the spawned
+ # processes.
+ # env.create() should install the just created setuptools
+ # wheel, but it doesn't if it finds another existing matching setuptools
+ # installation present on PYTHONPATH:
+ # `setuptools is already installed with the same version as the provided
+ # wheel. Use --force-reinstall to force an installation of the wheel.`
+ # This prevents leaking PYTHONPATH to the created environment.
+ with contexts.environment(PYTHONPATH=None):
+ return env.create()
+
+
+@pytest.fixture
+def venv_without_setuptools(tmp_path):
+ """Virtual env without any version of setuptools installed"""
+ env = environment.VirtualEnv()
+ env.root = path.Path(tmp_path / 'venv_without_setuptools')
+ env.create_opts = ['--no-setuptools']
+ env.ensure_env()
+ return env
+
+
+@pytest.fixture
+def bare_venv(tmp_path):
+ """Virtual env without any common packages installed"""
+ env = environment.VirtualEnv()
+ env.root = path.Path(tmp_path / 'bare_venv')
+ env.create_opts = ['--no-setuptools', '--no-pip', '--no-wheel', '--no-seed']
+ env.ensure_env()
+ return env