behave as no .venv if .venv is in project root and empty

This commit is contained in:
kobayashi
2021-10-03 01:03:04 -04:00
parent 9378cb5151
commit f26c9b5235
2 changed files with 34 additions and 0 deletions
+4
View File
@@ -270,6 +270,10 @@ class Project:
with io.open(dot_venv) as f:
name = f.read().strip()
# If .venv file is empty, set location based on config.
if not name:
return str(get_workon_home().joinpath(self.virtualenv_name))
# If content looks like a path, use it as a relative path.
# Otherwise use directory named after content in WORKON_HOME.
if looks_like_dir(name):
+30
View File
@@ -76,6 +76,36 @@ def test_venv_file(venv_name, PipenvInstance):
assert venv_path == normalize_drive(venv_expected_path)
@pytest.mark.dotvenv
def test_empty_venv_file(PipenvInstance):
"""Tests virtualenv creation when a empty .venv file exists at the project root
"""
with PipenvInstance(chdir=True) as p:
file_path = os.path.join(p.path, '.venv')
with open(file_path, 'w') as f:
pass
with temp_environ(), TemporaryDirectory(
prefix='pipenv-', suffix='temp_workon_home'
) as workon_home:
os.environ['WORKON_HOME'] = workon_home.name
if 'PIPENV_VENV_IN_PROJECT' in os.environ:
del os.environ['PIPENV_VENV_IN_PROJECT']
c = p.pipenv('install')
assert c.returncode == 0
c = p.pipenv('--venv')
assert c.returncode == 0
venv_loc = Path(c.stdout.strip()).absolute()
assert venv_loc.exists()
assert venv_loc.joinpath('.project').exists()
from pathlib import PurePosixPath
venv_path = normalize_drive(venv_loc.as_posix())
venv_path_parent = str(PurePosixPath(venv_path).parent)
assert venv_path_parent == Path(workon_home.name).absolute().as_posix()
@pytest.mark.dotvenv
def test_venv_file_with_path(PipenvInstance):
"""Tests virtualenv creation when a .venv file exists at the project root