summaryrefslogtreecommitdiff
path: root/setuptools/tests/environment.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/tests/environment.py')
-rw-r--r--setuptools/tests/environment.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/setuptools/tests/environment.py b/setuptools/tests/environment.py
index c0274c33..bcf29601 100644
--- a/setuptools/tests/environment.py
+++ b/setuptools/tests/environment.py
@@ -1,9 +1,38 @@
import os
import sys
+import subprocess
import unicodedata
-
from subprocess import Popen as _Popen, PIPE as _PIPE
+import jaraco.envs
+
+
+class VirtualEnv(jaraco.envs.VirtualEnv):
+ name = '.env'
+ # Some version of PyPy will import distutils on startup, implicitly
+ # importing setuptools, and thus leading to BackendInvalid errors
+ # when upgrading Setuptools. Bypass this behavior by avoiding the
+ # early availability and need to upgrade.
+ create_opts = ['--no-setuptools']
+
+ def run(self, cmd, *args, **kwargs):
+ cmd = [self.exe(cmd[0])] + cmd[1:]
+ kwargs = {"cwd": self.root, **kwargs} # Allow overriding
+ # 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 and
+ # - no custom env is explicitly set by a test
+ # PYTHONPATH will leak into the spawned processes.
+ # In that case tests look for module in the wrong place (on PYTHONPATH).
+ # Unless the test sets its own special env, pass a copy of the existing
+ # environment with removed PYTHONPATH to the subprocesses.
+ if "env" not in kwargs:
+ env = dict(os.environ)
+ if "PYTHONPATH" in env:
+ del env["PYTHONPATH"]
+ kwargs["env"] = env
+ return subprocess.check_output(cmd, *args, **kwargs)
+
def _which_dirs(cmd):
result = set()