pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.5k stars 1.19k forks source link

CalledProcessError in test_pip_upgrade_from_source[pip==9.0.3] #1734

Open jaraco opened 5 years ago

jaraco commented 5 years ago

When running tests on master using macOS and Python 3.7.3 with tox-venv installed, I get this error:

setuptools master $ tox -r -- -k test_pip_upgrade_from_source                                                                                                                  
python recreate: /Users/jaraco/code/main/setuptools/.tox/python
python installdeps: -rtests/requirements.txt
python develop-inst: /Users/jaraco/code/main/setuptools
python installed: action: python, msg: envreport,cwd: /Users/jaraco/code/main/setuptools,cmd: /Users/jaraco/code/main/setuptools/.tox/python/bin/pip freeze,apipkg==1.5,atomicwrites==1.3.0,attrs==19.1.0,contextlib2==0.5.5,coverage==4.5.3,entrypoints==0.3,execnet==1.6.0,flake8==3.7.7,importlib-metadata==0.9,mccabe==0.6.1,mock==2.0.0,more-itertools==7.0.0,path.py==11.5.0,Paver==1.3.4,pbr==5.1.3,pluggy==0.9.0,py==1.8.0,pycodestyle==2.5.0,pyflakes==2.1.1,pytest==3.10.1,pytest-cov==2.6.1,pytest-fixture-config==1.4.0,pytest-flake8==1.0.4,pytest-shutil==1.6.0,pytest-virtualenv==1.6.0,six==1.12.0,termcolor==1.1.0,virtualenv==16.4.3,zipp==0.3.3
python run-test-pre: PYTHONHASHSEED='1449201196'
python run-test: commands[0] | pytest --cov-config=/Users/jaraco/code/main/setuptools/tox.ini --cov-report= -k test_pip_upgrade_from_source
============================================================================= test session starts =============================================================================
platform darwin -- Python 3.7.3, pytest-3.10.1, py-1.8.0, pluggy-0.9.0
rootdir: /Users/jaraco/code/main/setuptools, inifile: pytest.ini
plugins: virtualenv-1.6.0, shutil-1.6.0, flake8-1.0.4, cov-2.6.1
collected 672 items / 666 deselected / 2 skipped                                                                                                                              

setuptools/tests/test_virtualenv.py .F....                                                                                                                              [100%]

================================================================================== FAILURES ===================================================================================
__________________________________________________________________ test_pip_upgrade_from_source[pip==9.0.3] ___________________________________________________________________

pip_version = 'pip==9.0.3', virtualenv = <pytest_virtualenv.VirtualEnv object at 0x10983b4e0>

    @pytest.mark.parametrize('pip_version', _get_pip_versions())
    def test_pip_upgrade_from_source(pip_version, virtualenv):
        """
        Check pip can upgrade setuptools from source.
        """
        # Install pip/wheel, and remove setuptools (as it
        # should not be needed for bootstraping from source)
        if pip_version is None:
            upgrade_pip = ()
        else:
            upgrade_pip = ('python -m pip install -U {pip_version} --retries=1',)
        virtualenv.run(' && '.join((
            'pip uninstall -y setuptools',
            'pip install -U wheel',
        ) + upgrade_pip).format(pip_version=pip_version))
        dist_dir = virtualenv.workspace
        # Generate source distribution / wheel.
        virtualenv.run(' && '.join((
            'cd {source}',
            'python setup.py -q sdist -d {dist}',
            'python setup.py -q bdist_wheel -d {dist}',
        )).format(source=SOURCE_DIR, dist=dist_dir))
        sdist = glob.glob(os.path.join(dist_dir, '*.zip'))[0]
        wheel = glob.glob(os.path.join(dist_dir, '*.whl'))[0]
        # Then update from wheel.
>       virtualenv.run('pip install ' + wheel)

setuptools/tests/test_virtualenv.py:114: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/python/lib/python3.7/site-packages/pytest_virtualenv.py:151: in run
    return super(VirtualEnv, self).run(args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pytest_virtualenv.VirtualEnv object at 0x10983b4e0>
cmd = 'pip install /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi8l8lgtp/setuptools-40.9.0.post20190405-py2.py3-none-any.whl', capture = False, check_rc = True
cd = Path('/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi8l8lgtp'), shell = True
kwargs = {'env': {'COVERAGE_FILE': '/Users/jaraco/code/main/setuptools/.tox/.coverage.python', 'LANG': 'en_US.UTF-8', 'PATH': '..., 'PYTEST_CURRENT_TEST': 'setuptools/tests/test_virtualenv.py::test_pip_upgrade_from_source[pip==9.0.3] (setup)', ...}}
p = <subprocess.Popen object at 0x10983b978>, out = None, _ = None
err = CalledProcessError(1, 'pip install /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi8l8lgtp/setuptools-40.9.0.post20190405-py2.py3-none-any.whl')

    def run(self, cmd, capture=False, check_rc=True, cd=None, shell=False, **kwargs):
        """
        Run a command relative to a given directory, defaulting to the workspace root

        Parameters
        ----------
        cmd : `str` or `list`
            Command string or list. Commands given as a string will be run in a subshell.
        capture : `bool`
            Capture and return output
        check_rc : `bool`
            Assert return code is zero
        cd : `str`
            Path to chdir to, defaults to workspace root
        """
        if isinstance(cmd, string_types):
            shell = True
        else:
            # Some of the command components might be path objects or numbers
            cmd = [str(i) for i in cmd]

        if not cd:
            cd = self.workspace

        with cmdline.chdir(cd):
            log.debug("run: {0}".format(cmd))
            if capture:
                p = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs)
            else:
                p = subprocess.Popen(cmd, shell=shell, **kwargs)
            (out, _) = p.communicate()

            if out is not None and not isinstance(out, string_types):
                out = out.decode('utf-8')

            if self.debug and capture:
                log.debug("Stdout/stderr:")
                log.debug(out)

            if check_rc and p.returncode != 0:
                err = subprocess.CalledProcessError(p.returncode, cmd)
                err.output = out
                if capture and not self.debug:
                    log.error("Stdout/stderr:")
                    log.error(out)
>               raise err
E               subprocess.CalledProcessError: Command 'pip install /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi8l8lgtp/setuptools-40.9.0.post20190405-py2.py3-none-any.whl' returned non-zero exit status 1.

.tox/python/lib/python3.7/site-packages/pytest_shutil/workspace.py:132: CalledProcessError
---------------------------------------------------------------------------- Captured stdout setup ----------------------------------------------------------------------------
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.7'
New python executable in /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi8l8lgtp/.env/bin/python3.7
Also creating executable in /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi8l8lgtp/.env/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
---------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------
Uninstalling setuptools-40.9.0:
  Successfully uninstalled setuptools-40.9.0
Requirement already up-to-date: wheel in ./.env/lib/python3.7/site-packages (0.33.1)
Collecting pip==9.0.3
  Using cached https://files.pythonhosted.org/packages/ac/95/a05b56bb975efa78d3557efa36acaf9cf5d2fd0ee0062060493687432e03/pip-9.0.3-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 19.0.3
    Uninstalling pip-19.0.3:
      Successfully uninstalled pip-19.0.3
Successfully installed pip-9.0.3
---------------------------------------------------------------------------- Captured stderr call -----------------------------------------------------------------------------
warning: no previously-included files found matching 'pyproject.toml'
warning: no previously-included files found matching 'pyproject.toml'
Traceback (most recent call last):
  File "/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpi8l8lgtp/.env/bin/pip", line 6, in <module>
    from pip import main
ImportError: cannot import name 'main' from 'pip' (/Users/jaraco/code/main/setuptools/.tox/python/lib/python3.7/site-packages/pip/__init__.py)
=========================================================================== short test summary info ===========================================================================
SKIP [2] /Users/jaraco/code/main/setuptools/setuptools/tests/test_msvc.py:18: could not import 'distutils.msvc9compiler'
======================================================= 1 failed, 5 passed, 2 skipped, 666 deselected in 65.18 seconds ========================================================
ERROR: InvocationError for command /Users/jaraco/code/main/setuptools/.tox/python/bin/pytest --cov-config=/Users/jaraco/code/main/setuptools/tox.ini --cov-report= -k test_pip_upgrade_from_source (exited with code 1)
___________________________________________________________________________________ summary ___________________________________________________________________________________
ERROR:   python: commands failed
jaraco commented 5 years ago

Removing tox-venv from the development environment works around the issue. The issue seems to be related to an interaction between setuptools' tests running in a venv and creating virtualenvs from that venv.

jaraco commented 5 years ago

This issue is very similar to #1284, almost a duplicate, and this comment is pertinent.