Skip to content

Commit

Permalink
Merge pull request #2437 from frostming/bugfix/1901-tests
Browse files Browse the repository at this point in the history
Add test case for #1901
  • Loading branch information
techalchemy authored Jun 27, 2018
2 parents 4e1e847 + 698c9be commit bf5b330
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,18 @@ def __init__(self, python_version, python_path):
self.python_path = python_path

def __enter__(self):
os.environ['PIP_PYTHON_VERSION'] = str(self.python_version)
os.environ['PIP_PYTHON_PATH'] = str(self.python_path)
# Only inject when the value is valid
if self.python_version:
os.environ['PIP_PYTHON_VERSION'] = str(self.python_version)
if self.python_path:
os.environ['PIP_PYTHON_PATH'] = str(self.python_path)

def __exit__(self, *args):
# Restore original Python version information.
del os.environ['PIP_PYTHON_VERSION']
try:
del os.environ['PIP_PYTHON_VERSION']
except KeyError:
pass


def prepare_pip_source_args(sources, pip_args=None):
Expand Down
17 changes: 16 additions & 1 deletion tests/integration/test_lock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import os
import six

from pipenv.utils import temp_environ

Expand Down Expand Up @@ -331,7 +332,7 @@ def test_lock_updated_source(PipenvInstance, pypi):
@pytest.mark.lock
@pytest.mark.vcs
@pytest.mark.needs_internet
def lock_editable_vcs_without_install(PipenvInstance, pypi):
def test_lock_editable_vcs_without_install(PipenvInstance, pypi):
with PipenvInstance(pypi=pypi, chdir=True) as p:
with open(p.pipfile_path, 'w') as f:
f.write("""
Expand All @@ -345,3 +346,17 @@ def lock_editable_vcs_without_install(PipenvInstance, pypi):
assert 'chardet' in p.lockfile['default']
c = p.pipenv('install')
assert c.return_code == 0


@pytest.mark.lock
def test_lock_respecting_python_version(PipenvInstance, pypi):
with PipenvInstance(pypi=pypi) as p:
with open(p.pipfile_path, 'w') as f:
f.write("""
[packages]
django = "*"
""".strip())
django_version = '==2.0.6' if six.PY3 else '==1.11.10'
c = p.pipenv('lock')
assert c.return_code == 0
assert p.lockfile['default']['django']['version'] == django_version
Binary file added tests/pypi/django/Django-2.0.6.tar.gz
Binary file not shown.

0 comments on commit bf5b330

Please sign in to comment.