diff options
author | Paul Ganssle <paul@ganssle.io> | 2019-02-07 09:28:29 -0500 |
---|---|---|
committer | Paul Ganssle <paul@ganssle.io> | 2019-02-23 11:38:50 -0600 |
commit | b224605a8c16b2a713120bf0d484fa12ce781f02 (patch) | |
tree | 17e76a51c05429523a18bb1ca459e4e6bcea5443 /setuptools/tests | |
parent | 82db4c621974659513effae337d47a05e31fe7a5 (diff) | |
download | external_python_setuptools-b224605a8c16b2a713120bf0d484fa12ce781f02.tar.gz external_python_setuptools-b224605a8c16b2a713120bf0d484fa12ce781f02.tar.bz2 external_python_setuptools-b224605a8c16b2a713120bf0d484fa12ce781f02.zip |
Automatically skip tests that require network
Diffstat (limited to 'setuptools/tests')
-rw-r--r-- | setuptools/tests/test_virtualenv.py | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/setuptools/tests/test_virtualenv.py b/setuptools/tests/test_virtualenv.py index bd89fd64..d7b98c77 100644 --- a/setuptools/tests/test_virtualenv.py +++ b/setuptools/tests/test_virtualenv.py @@ -52,24 +52,55 @@ def test_clean_env_install(bare_virtualenv): )).format(source=SOURCE_DIR)) -@pytest.mark.parametrize('pip_version', ( - 'pip==9.0.3', - 'pip==10.0.1', - 'pip==18.1', - 'pip==19.0.1', - 'https://github.com/pypa/pip/archive/master.zip', -)) -def test_pip_upgrade_from_source(virtualenv, pip_version): +def _get_pip_versions(): + # This fixture will attempt to detect if tests are being run without + # network connectivity and if so skip some tests + + network = True + if not os.environ.get('NETWORK_REQUIRED', False): # pragma: nocover + try: + from urllib.request import urlopen + from urllib.error import URLError + except ImportError: + from urllib2 import urlopen, URLError # Python 2.7 compat + + try: + urlopen('https://pypi.org', timeout=1) + except URLError: + # No network, disable most of these tests + network = False + + network_versions = [ + 'pip==9.0.3', + 'pip==10.0.1', + 'pip==18.1', + 'pip==19.0.1', + 'https://github.com/pypa/pip/archive/master.zip', + ] + + versions = [None] + [ + pytest.param(v, **({} if network else {'marks': pytest.mark.skip})) + for v in network_versions + ] + + return versions + + +@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', - 'python -m pip install {pip_version}', - )).format(pip_version=pip_version)) + ) + upgrade_pip).format(pip_version=pip_version)) dist_dir = virtualenv.workspace # Generate source distribution / wheel. virtualenv.run(' && '.join(( |